documentation:perl
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
documentation:perl [2010/05/20 05:37] – triley2 | documentation:perl [2010/05/20 09:50] (current) – triley2 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP left 40%> | ||
+ | ~~TOC~~ | ||
+ | </ | ||
+ | // | ||
+ | // | ||
+ | <WRAP centeralign 100% bigger> | ||
+ | <WRAP bigger fgred> | ||
+ | <WRAP muchbigger> | ||
+ | Programing Language | ||
+ | </ | ||
+ | <WRAP clear></ | ||
+ | created in 1987 as a UNIX scripting language Perl has influences from c/c++, sed and unix shell scripting. It is now a full featured high-level programing language that makes text manipulation simple. Perl is also used in dynamic web page creation and report generation. understanding of UNIX shell commands and regular expressions are essential to take full advantage of the Perl language. | ||
+ | ===== First Program ===== | ||
+ | <code perl> | ||
+ | # | ||
+ | | ||
+ | print "hello world!"; | ||
+ | </ | ||
+ | |||
+ | save as hello.pl | ||
+ | |||
+ | run | ||
+ | <cli> | ||
+ | perl hello.pl | ||
+ | </ | ||
+ | ===== Common Commands ===== | ||
+ | ==Data Types== | ||
+ | * $ - scalar variable | ||
+ | * @ - array variable | ||
+ | * % - hash | ||
+ | * & - subroutine | ||
+ | ==Input, Output, Comments== | ||
+ | * # - comment | ||
+ | * print - print to the screen | ||
+ | * < | ||
+ | * chomp - remove newline character | ||
+ | ==Arithmetic Operators== | ||
+ | * + - add | ||
+ | * * - multiply | ||
+ | * % - modulus | ||
+ | * ** - exponent | ||
+ | * . - concatenate | ||
+ | * x - repeat | ||
+ | * = - assignment operator | ||
+ | ==Logical Operators== | ||
+ | *&& or and - and | ||
+ | *|| or or - or | ||
+ | *! or not - not | ||
+ | *== or eq - equal | ||
+ | *!= or ne - not equal | ||
+ | *< or lt - less than | ||
+ | *> or gt - greater than | ||
+ | *<= or le - less than or equal too | ||
+ | *>= or ge - greater than or equal too | ||
+ | *<=> or cpm - compare | ||
+ | ==If Structure== | ||
+ | <code perl> | ||
+ | if ($var > 0) | ||
+ | { | ||
+ | print " | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | print " | ||
+ | } | ||
+ | </ | ||
+ | ==For Loop== | ||
+ | <code perl> | ||
+ | for ($var = 0; $var < 10; $var++) | ||
+ | { | ||
+ | print "this is a loop"; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Input output program ===== | ||
+ | <code perl> | ||
+ | # | ||
+ | |||
+ | my $name; | ||
+ | my $num; | ||
+ | |||
+ | print "What is your name: "; | ||
+ | $name = < | ||
+ | chomp($name); | ||
+ | for ($num = 0; < 10; $num++) | ||
+ | { | ||
+ | print $num." "; | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | |||
+ | </ | ||
+ | ===== Links ===== | ||
+ | *www.perl.org |