logo.jpg (4128 bytes)
Home
Main Page
Links
Classical
Popular
Programming
Shareware
Emulation
Opus
Gtr & Fl.
Concerto
Code
Status bar
Math
Perl
Base Address
Meta Script
DHTML
WSC
Programs
Markup
Clipboard

 

Perl Reference

This is a small Perl quick-reference that will be growing as I learn Perl. When I learn new things about Perl, I will add them here to serve as a reminder, and also to enforce the knowledge. This is in NO way to be considered a tutorial. If you are looking for a Perl tutorial, try this one. If you're looking for Perl for Windows information, go here.

Click on a topic heading to expand the list.

retracted.jpg (1037 bytes)

Arrays

bulletb.jpg (896 bytes) Declaration: @identifier = (element1, element2...);
bulletb.jpg (896 bytes) Accessing elements: $identifier[0 to length of array];
bulletb.jpg (896 bytes) push(): push(@identifier, element); Adds elements to end, and returns the new length.
bulletb.jpg (896 bytes) pop(): pop(@identifier); Removes last element and returns it.
bulletb.jpg (896 bytes) Index of last element: $#Identifier;
bulletb.jpg (896 bytes) Printing all elements: "@identifier"; Prints each element separated by a space.
bulletb.jpg (896 bytes) For multiple assignments:
     ($a, $b) = ($c, $d); same as $a = $c; $b = $d;
     ($a, $b) = @Identifier; Assigns first two elements of @Identifier to $a and $b respectively.
     ($a, @OtherIdentifier = @Identifier; Assigns first element to $a, and the rest to @OtherIdentifier.

retracted.jpg (1037 bytes)

Loops

bulletb.jpg (896 bytes) For Each loop: for each $a (@Identifier) { statements... }
bulletb.jpg (896 bytes) For structure: for ($counter = 0; $counter > qualifier; $counter++) { statements... }
bulletb.jpg (896 bytes) While loop: while (condition) { statements... }
bulletb.jpg (896 bytes) Until loop: until (condition is true) { statements... }
bulletb.jpg (896 bytes) Do While loop: do { statements... } while (condition)

retracted.jpg (1037 bytes)

Conditionals

bulletb.jpg (896 bytes) Equality: $a == $b; Numerically equal; $a != $b; Numerically unequal; $a eq $b; String-equal; $a ne $b String-unequal;
bulletb.jpg (896 bytes) Logical: ($a && $b); Logical And; ($a || $b); Logical Or; !($a); Logical Not;

retracted.jpg (1037 bytes)

Regular Expressions

bulletb.jpg (896 bytes) String Matching: /expression/ matching occurs with the =~ operator; $sentence =~ /RE/;
bulletb.jpg (896 bytes) Non Matching: non-matching occurs with the !~ operator; $sentence !~ /RE/;
bulletb.jpg (896 bytes) $_: Assign $sentence to $_ then $sentence can be omitted from the expression; /RE/;
bulletb.jpg (896 bytes) Special Characters:
     . Any single character other than newline; ^ beginning of a newline; $ end of a line;
      * zero or more of the last character; + one or more of the last character; ? zero or one of the last character
bulletb.jpg (896 bytes) With Square Brackets:
     [abc] either a, b, or c; [^abc] neither a, b, nor c; [a-z] anything from a to z inclusive (lowercase);
     [^a-z] no lowercase letters; [a-zA-Z] any letters; [a-z]+ any non-zero sequence of lowercase letters;
bulletb.jpg (896 bytes) With a Vertical Bar "|" or Parenthesis:
     jelly|cream either jelly or cream; (eg|le)gs eggs or legs; (da)+ either da or dada or dadada...
bulletb.jpg (896 bytes) Other Special Operators:
     \n newline; \t tab character; \w any alphanumeric (word) character [a-zA-Z0-9_]; \W any non-word character
     \s any whitespace character space, tab, newline, etc. \S any non-whitespace character.
     \b word boundaries; \B no word boundary;
bulletb.jpg (896 bytes) Escape Sequences:
     \| a vertical bar; \[ open square bracket; \) a closing parenthesis; \* an asterisk;
     \^ a carat; \/ a slash; \\ a backslash and so on.

retracted.jpg (1037 bytes)

String Functions

bulletb.jpg (896 bytes) Split(): @Identifier = split(/RE/, $Identifier); Or $_ = $Identifier; @Identifier = split(/RE/);
     creates an array from a string, each element separated by character(s) indicated by /RE/
bulletb.jpg (896 bytes) Substr(): $Identifier = substr($s, [-]$nStart, [$nLength]);

 

hr.jpg (7889 bytes)

 
Aaron L. Stephanus Do YOU want YOUR choice of a FREE laptop ?