<Perl 5 is not tackled here>
Though there may be many net resources for Perl, I would strongly recommend the book:
Programming Perl Larry Wall and Randall L. Schwartz O'Reilly & Associates, Inc ISBN 0-937175-64-1
$name; a string or a number @name; a list %name; an associative arrayAll variables appear to global unless you declare them as local to a subroutines
( string1 eq string2 ) true if both strings are equal ( string1 ne string2 ) true if both strings are different
$a = "some text ${variable}\n"; $a = "${variable1}${variable2}";
ge, gt, le, lt
sub my_sub { local ( $var1, @my_array, %my_assoc_array); #declare locals # # Do your processing in here # return (whatever); }If you pass arguments to a subroutine you can initialise them using the @_ array. This array is constructed from the arguments to the subroutine.
local ( $var1, $var2, %my_assoc_array)= @_; #read args
if ( condition) { } elsif ( condition2) { } elsif (.... .. else { }
for ( <init>; <condition>;<increment> ) { } foreach $i ( 1,2,3,4,54,...) { } foreach $i ( @list ) { }
while ( condition ) { } do { } until ( condition);
if ( $myvar =~ /expression/ ) { # contents of variable match }
$myvar =~ s/expression1/expression2/g;
# #$myvar =~ tr/set1/set2/; # $myvar =~ tr/[A-Z]/[a-z]/; #lowercase
regular expressions are extended in Perl:
a* 0 or more occurances of a a+ 1 or more occurances of a \s whitespace \S non-whitespace \w alphanumeric \W non alpha-numeric
The key_name can be a quoted string or a variable
#-----------------------basics---------------------------- %array_name = ( #initialise key1, value1, key2, value2, ..., keyn, valuen); ); $array_name{key_name} = value; #associate $value = $array_name{key_name}; #lookup #----------------------- using ------------------------------- @key_array = keys %array_name; #get a list of keys @key_array = sort (keys %array_name); foreach $key ( keys %array_name ) #process each key { $value = $array_name{$key}; #get value }