names
$cents scalar
@large array
%interest hash
&how subroutine (a.k.a. function)
|
# A comment is helpful.
|
generic expressions
$s ? $x : $y
($x)
|
numbers
0, 1, -1, ...
1.0, 2.0, 1.5, 0.6666, ...
$a + $b
$a - $b
- $a
$a * $b
$a / $b
abs $a
$a ** $b
sin $a [etc.]
|
strings
"whatever"
"specials \" \n \$"
$s . $t
$red = substr("get the red out", 8, 3);
|
arrays
@a = ($a, $b);
($a, $b) = @a;
$size = scalar(@a);
$elem = @a[$idx];
|
functions
&funcname($x, $y);
sub funcname {
my ($x, $y) = @_;
action1;
action2;
return ... $x ...;
}
|
sentences
0 false
1 true
$a == $b numeric
$a != $b numeric
$a < $b numeric
$a <= $b numeric
$a >= $b numeric
$a > $b numeric
$a eq $b string
$a ne $b string
$a lt $b string
$a le $b string
$a ge $b string
$a gt $b string
$s and $t
$s or $t
not $s
|
actions
if ($s) {
action1;
}
elsif ($t) {
action2;
}
else {
action3;
}
for ($k = 0; $k < $n; $k = $k += 1) {
action;
}
foreach $user (@users) {
action;
}
$x = $y;
$ch = getc;
$line = <STDIN>;
print "$str\n";
|