perl -v | the version of perl running (most recent from www.activestate.com) |
perl -c | check syntax but don't run |
perl -w | check program more thoroughly than -c |
perl -e "code;" | run one line program |
perl -i | use perl to edit files |
perl -d | perl's debugger |
#!/usr/bin/perl -w | first line in code on Unix |
Variable Names: Case-sensitive. Any Length. A-z and Underscores. Can't start with a number.
# | comment -- starts anywhere on the line | |
= | set value on left to value on right | |
; | statement end. not required at the end of a block. | |
{} | beginning and end of block. can be embedded. | |
. | open(INFILE,$TheFile) or die "The file $TheFile could ". | concatenation |
+ | $variable = $variable + 1; | add values on right and store in variable on the left |
$0 | the name of the program that is running | |
$_ | $TheLine = $_; | Save the line's contents |
\n | line break | |
++ | $LineCount++; | Increment value |
/t | tab | |
hex | \x42 = B | |
octal | \102 = B | |
chr | $CapB = chr(66); | |
STDIN | my $SearchValue = <STDIN>; | What user has typed |
tr | $DoSearch =~ tr/A-Z/a-z/; | translate value to lowercase |
print "some text and $variable \n"; | ||
length | $varLength = length($variable2); | |
open | open(filehandle,$filename) or die("message to display if not found \n"); | Open file. If not able, post message |
substr | $var = substr($Line,$PosFromZero,$Len); | substring |
chomp | chomp($TheLine); | get rid of the line break |
seek | seek(INDB,0,0); | Tells Perl where in the file to start |
split | ($Var1, $Var2) = split(/\t/, $TheRec); | split a string based on a value into separate variables |
While Loop | while( while(1) my $Search = |
Until Loop | until ($var1 == $var2) |
If | if ($variable eq "value") if ($TheLine = "") if ($Cntr == 0) |
Unless | unless($DoSearch eq 'i') { print "Enter I or Q.\n"; next; } |
For | for ($i = 33; $i <=126; $i++) |
Last | if($SrchVal eq 'q') {last} |
Next | if($TheLine = "") {next}; |
' vs "
'
"
print 'Lynn\'s programs are on usr\\user\\ltobias.';
Lynn's programs are on usr\user\ltobias.
$Shout = "Help!";
print "Please come when I shout \"$Shout\". \n";
Please come when I shout "Help!".
$Value = "something";
print "\$Value is $Value. \n";
$Value is something.
No comments:
Post a Comment