II —:::— Cocoa

arrays.pl

A UNIX Command
$cat arrays.pl
# Simple array constructs.
@fred = ("How", "are", "you", "today?");
print "\@fred contains (@fred).\n";

$mike = $fred[1];
print "$mike $fred[3]\n";

# The array name in a scalar context gives the size.
$fredsize = @fred;
print '@fred has ', "$fredsize elements.\n";

# The $#name gives the max subscript (size less one).
print "Max sub is $#fred\n";

$perl arrays.pl
@fred contains (How are you today?).
are today?
@fred has 4 elements.
Max sub is 3
$

UNIX Explanation
Variables whose names begin with @ are arrays. If @sue is
an array,  it is  different variable from  $sue. However,
members   of  @sue   are  selected   by   $sue[$i].   The
construction $#arrname gives the maximum subscript of the
array @arrname.

source : http://sandbox.mc.edu/~bennet/perl/leccode/var2_pl.html

cat + grep + wc and pipe operator

A UNIX Command
$ls
1984  2001  2004  2007	2010		 TED-talks-grouped-by-year-in-high-quality.metalink
1990  2002  2005  2008	2011		 ted_urls
1998  2003  2006  2009	ted_download.sh
$cat TED-talks-grouped-by-year-in-high-quality.metalink | grep -w url | wc -l
980
$

UNIX Explanation
This command finds out the  number of lines with the word
"url" in the file TED*.

scalar.pl —-x strings

A UNIX Command
$perl scalar.pl
The variable $fred contains Fred here.
Sum is 66.
$cat scalar.pl
$fred = "Fred here";
$barney = 56;
$sum = 10 + $barney;
print 'The variable $fred' . " contains $fred.\n";
print "Sum is $sum.\n";

$cat scalar.pl
$fred = "Fred here";
$barney = 56;
$sum = 10 + $barney;
print 'The variable $fred.' . " contains $fred.\n";
print "Sum is $sum.\n";

$perl scalar.pl
The variable $fred. contains Fred here.
Sum is 66.
$cat scalar.pl
$fred = "Fred here";
$barney = 56;
$sum = 10 + $barney;
print "The variable $fred." . " contains $fred.\n";
print "Sum is $sum.\n";

$perl scalar.pl
The variable Fred here. contains Fred here.
Sum is 66.
$

UNIX Explanation
Various operations on scalar (string) variables.

source: http://sandbox.mc.edu/~bennet/perl/leccode/var1_pl.html