Perl Doc
Perl Doc
while ($v=<bin/*> {
@a-readdir(ETC);
mkdir ("bin",0777) || die "cannot make dir bin" (x-1 w-2 r-4];
System Processing
system ("who >file") && die "cannot create file right now"; return of true (nonzero) is an error -
opposite of Perl therefore && instead
of ||
Regular Expressions
if (/abc/) { search for string "abc"; print line which "abc" occurs; S_ is the default
variable
print "$_";
if (/abc/) {
/ca*t/ matches "ca" any number of "a's" and "t" matches any character but \n
/c.*?t/ the? suppresses greedy: cat but not cattt any char from present to end of
the line
s/ant(.)/bug\1/ \1 gets paren value (12 gets second paren) if ants then bugs; if anto then
bugo (second parens referenced with \2)
\b word boundary
$a="real food";
srand
-------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------
%map = ("pete", "xx"", "jo", "yy", "ida", "zz") create associative array (pairs of values)
keys(%map) lists keys of %map (e.g. use with foreach) in a scalar context returns no. of keys
-------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------
String Fanctions
ne, It, gt, le, ge, cmp (returns -1, 0, or 1) these are the other string operators
-------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------
Print
$v = sprintf("%10s \n", $str); $v gets print string: like printf
printf ("%20s %4d %6.2f\n", $s, $i, $r); Same as "C" printf; %20s for string, 4d for decimal
integer, %6.2f for floating point.
-------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------
$v=45 value of $v is 45
($a,$b,$c)=(2,4,6) $a is 2, $b is 4, $c is 6
$b=$w[1] $b is now 0
@v = (2,3,1,11) initialize@v
@v=(aa,bb,cc) initialize@v
Control Operators
sub do_it { creates subroutine with local varsSv and @a
local ($v,@a);
$v=1} subroutine returns last expression evaluated
if (/a/ && /e/ && /i/ && /o/ &&/u/) {print "all vowels used";}
logical "and"
unless (cxpr) { executes unless expr is true statement list}
statement list } takes elsif and else (like if)
while(expr) { while expr is true repest execution of statement list
statement list}
statement list}
for (ini, test,incr) { initialize a variable, test to run list,
@w=(1..9);
foreach $v(@w) { prints 1 through 9 on separate lines print $vin;}
print $v\n;}
foreach (@w){
print$_;}
File Operators
ореn (FL, "fl"); open input file fl with filehandle FL
<STDOUT>
<STDERR>
-w writable
-x executable
-o owned by user
-e exists
-f file
-d directory
-l symlink
-T text file
-B binary file
\n newline
\t tab
\007 octal value (007= beli)