|
|
|
|
|
|
scalar |
$name |
a single value (string, numeric, etc.) |
|
|
list |
() |
ordered scalar data |
|
|
array |
@name |
a variable that holds a list |
|
|
hash |
%name |
a set of keys and elements |
|
|
symbol |
example(s) |
action |
|---|---|---|
|
|
$a=$b; $a=4; |
assignment |
|
|
$a=~/regex/ |
performs regular expression match, substitute |
|
|
$str = $str . "b"; $str.="b"; #same thing |
string concatenate |
|
|
||
|
|
||
|
|
||
|
|
|
prqagma |
meaning |
|---|---|
|
use strict; |
generate error if varialbes not declared with my() |
|
Name |
Argument(s) Type |
Result Type |
Action |
|---|---|---|---|
|
qw |
comma-separated strings |
list |
double-quotes arguments |
|
push |
list,scalar |
appends 'scalar' to 'list' |
|
|
pop |
|||
|
shift |
|||
|
unshift |
|||
|
reverse |
list |
list |
reverses order of list elements |
|
sort |
list |
list |
places elements in ascending ascii order |
|
chomp |
array or scalar variable |
removes last record separator from the scalar or from each element of the array |
|
|
<STDIN> |
n/a |
scalar or array, depending on context |
|
|
<> (diamond) |
|
as <STDIN> but refers to files listed in @argv |
|
|
rand |
scalar |
scalar |
returns a random number between zero and (argument-1) |
|
srand |
none |
none |
initializes the random number generator. |
|
keys |
hash |
list |
|
|
values |
hash |
list |
|
|
each |
hash |
2 element list |
returns the next successive key/value pair in the hash |
|
delete |
hash element |
n/a |
|
|
defined |
anything |
logical |
returns FALSE if argument is undef. (usually redundant?) |
|
split |
regex,string |
list |
|
|
join |
string,list |
string |
|
|
die "message\n"; |
terminate and print 'message' to STDERR. System error message appended unless \n included. |
||
|
warn "message"; |
as 'die' but don't terminate. |
||
|
|
|
my(list of variables ); |
variables entirely private to subroutine |
|
local(list of variables ); |
variables local to subroutine and decendants |
|
Symbol |
Meaning/Use |
Example |
|---|---|---|
|
|
Default variable |
default i/o target, foreach parameter, match string,... |
|
|
Subroutine argument list |
reference arguments as $_[n] within the subroutine |
|
open(HANDLE,">filename"); |
Opens a file for reading. Prefix '>' or '>>' opens to write. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
close(HANDLE); |
Closes file (happens automatically if re-opened or at termination of program) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
die "message\n"; warn "mess"; |
output to STDERR. 'die' terminates program. system message if no '\n' |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
<STDIN>, <STDOUT> |
default filehandles for IO |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
print [FILEHANDLE] item1,item2,... |
write to FILEHANDLE |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
File Tests $readable= -r $filename; $age= -M "/usr/bin/perl"; |
|
|
Statement |
Format |
Comment |
|---|---|---|
|
if / unless elsif else |
|
Note it's spelled elsif, not elseif! |
|
while/until |
|
|
|
do {} while do {} until |
|
|
|
for |
|
|
|
foreach |
|
$i may be omitted in which case $_ is assumed. |
|
last [LABEL] |
last; |
breaks out of the innermost enclosing loop block, or out of the block LABEL . |
|
next [LABEL] |
next; |
skips remainder of innermost enclosing loop block without exiting the loop. If LABEL is present go to the beginning of the block LABEL. |
|
redo |
redo; |
jumps to beginning of the current loop block |
|
a |
a single character - matches only itself |
||||||||
|
. (dot) |
matches any single character except newline |
||||||||
|
/[aeiou]/, /[A-Z]/ |
character class. Matches any single mentioned character. |
||||||||
|
|
matches newline |
||||||||
|
|
octal representation |
||||||||
|
/[^0-9]/ |
negated character class |
||||||||
|
\d \w \s |
a digit, word-character, or space-character |
||||||||
|
|
NOT a digit, word, or space character |
||||||||
|
|
zero or more of the preceeding character |
||||||||
|
|
one or more of the preceeding character |
||||||||
|
|
zero or one of the preceeding character |
||||||||
|
|
"m" to "n" a's. |
||||||||
|
|
exactly "m" a's |
||||||||
|
|
"m" or more a's |
||||||||
|
|
items matched by parenthesized patterns may be used later in the pattern by '\n' where 'n' refers to the nth parenthesized pattern match. '$n' is a scalar containing the matched string which can be used elsewhere in the script after the pattern match. Use (?:pattern ) to prevent the memory function. |
||||||||
|
|
|
||||||||
|
|
match pattern 'a' or 'b' |
||||||||
|
|
anchors to a word boundary (NOT a word boundary) |
||||||||
|
|
requires 'a' as first character in string |
||||||||
|
|
requires 'a' as last character in string |
||||||||
|
|
anchors -- not yet described |
||||||||
|
|
matches against $a (instead of $_) |
||||||||
|
|
'm' indicates use '#' (or whatever follows) as delimeter instead of '/'. |
||||||||
|
|
read-only variables containing the part of the string before/in/following the match |
||||||||
|
|
substitute 'new' for 'old'. If 'g' is present, do substitution everywhere. |
||||||||
|
|
|
||||||||
|
|
uppercase (lowercase) the following letter or STRING. |