Wednesday, March 10, 2010

Miscellaneous Notes


perl -vthe version of perl running
(most recent from www.activestate.com)
perl -ccheck syntax but don't run
perl -wcheck program more thoroughly than -c
perl -e "code;"run one line program
perl -iuse perl to edit files
perl -d perl's debugger

#!/usr/bin/perl -wfirst 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 ".
"not be found. \n";
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);

STDINmy $SearchValue = <STDIN>; What user has typed
tr$DoSearch =~ tr/A-Z/a-z/;
translate value to lowercase
printprint "some text and $variable \n";
length$varLength = length($variable2);
openopen(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
chompchomp($TheLine);get rid of the line break
seekseek(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 Loopwhile() # while there are records in the file
{ $TheLine = $_; # save the line's contents
chomp($TheLine); # get rid of the line break

if($TheLine = "")
{next}; # don't count if the line is a blank
$LineCount++; # increment the line count
}; # end of block

while(1) # loop forever (1=true)
{ print "Y or N"; # show this line on the screen.
my $Search = ; # save what's typed
}; # end of block
Until Loopuntil ($var1 == $var2)
{ if ($var3 eq $var4)
{ do some statements }
}
If if ($variable eq "value")
{block of statements};
if ($TheLine = "")
{next} ; # don't count if the line is a blank
if ($Cntr == 0)
{print "zero"};
Unlessunless($DoSearch eq 'i') # If not 'i',
{ print "Enter I or Q.\n";
next; # Go back to 'while' for next try
}
Forfor ($i = 33;
$i <=126;
$i++)
{statements}
Lastif($SrchVal eq 'q') {last}
Nextif($TheLine = "") {next};



' vs "
'do not interpret (except for ' and \)
"interprets

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