...which in my experience is certainly the "Pathologically Eclectic Rubbish Lister"
Syntax:
http://perldoc.perl.org/perlsyn.html
Terminate all lines with semicolon (;) but not after blocks which are in
{}'s.
One = is assignment two = (==) is comparison, but it compares the numerical value when used with strings (e.g."abc" is converted to 0, "123" is converted to 123), and eq is really string comparison. Same with <, >, and lt, gt and with <=, >= and le, ge. != (numbers) is ne (string values). Wait till you get to <=> and cmp!
Comment out a sequence of lines by starting one with =pod and end the comment with =cut. POD is "Plain Old Documentation"1. Comment out a single line with the pound sign (#). as in
print "hello"; # will print #print "hello"; # will not print
Data:
http://perldoc.perl.org/perldata.html
References to variables start with $ if they are a single value of any type
(called a scalar, $ does NOT mean string) or @ if they are an array (or a
list) or % if they are a hash aka indexed array (% has nothing to do with
integers). $#array is index of last entry or approx # of entries in an Array.
keys(%hash) is count of keys in hash. No declarations are required.
Type casting is automatic. Preface the first reference to a variable with
my if you want it to be local.
Don't step on
the predefined variables! Examples
Values are replaced in a string constant enclosed with double quotes but not in one with single quotes.
A scalar value is interpreted as TRUE in the Boolean sense if it is not the null string or the number 0 (or its string equivalent, ``0''). There are actually two varieties of null strings (sometimes referred to as ``empty'' strings), a defined one and an undefined one. The defined version is just a string of length zero, such as "". The undefined version is the value that indicates that there is no real value for something, such as when there was an error, or at end of file, or when you refer to an uninitialized variable or element of an array or hash.
Parameters are optional (or rather there are default parameters). You can say while (<*.c>) { print; } and the names of all the .c files in the current directory will be printed. These names got from <*.c> to print via a thing refferred to as $_ If you don't specify a variable to hold a return value or supply a parameter value, it uses $_
The array @ARGV contains the command-line arguments intended for the script. $#ARGV is generally the number of arguments minus one, because $ARGV[0] is the first argument, not the program's command name itself.
Half of everything in Perl is regular expressions. They look like gibberish. I have yet to find a concise, complete, and understandable reference.
Statements: Note that the subscriped numbers show the order of execution in cases were that might be confusing.
Note that if, while, for, foreach are apparently not considered functions but rather modifiers for statements. In fact, the "statements" in the language can be extended, overridden, and augemented with the because a block of statements (in {} or a single statement) can be passed to a sub as a parameter. Sort of like passing a function but without any name to the function.
Shell to the os with a command enclosed in backticks (grave accents). e.g. `dir` will return each line of output as an element of an array and the status of the command as a scaler.
Functions: http://perldoc.perl.org/index-functions.html
$now_string = localtime; # e.g., "Thu Oct 13 04:54:34 2004"($sec,$min,$hour,$dayofmonth,$month,$year,$dayofweek,$dayofyear,$isDST) = localtime(time);
$year += 1900; #years since 1970 on a PC, since 1904 on a MAC.
$month++;$dayofyear++; #everything else is 0 based... err, except $dayofmonth
$weekday=('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[$dayofweek];
$YYYYMMDD=sprintf("%0.4d-%0.2d-%0.2d",$year,$month,$dayofmonth); # e.g. "2004-10-13"
$MMDDYY=sprintf("%0.2d/%0.2d/%0.2d",$month,$dayofmonth,$year % 100); # e.g. "10/13/04"
Encoding URLs (thanks to http://glennf.com/writing/hexadecimal.url.encoding.html )
sub URLEncode { my $theURL = $_[0]; $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg; return $theURL; }
Functions which can process a list of parameters seperated by commas can be completely fooled by parenta
A sample mailto.pl script
A sample http get script
a sample bbs_forum.pl script
See also:
Questions:
file: /Techref/language/perl/index.htm, 15KB, , updated: 2021/3/27 02:21, local time: 2024/12/26 23:45,
3.144.6.9:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/Techref/language/perl/index.htm"> PERL</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.