|
|||
#!/usr/bin/perl @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{ @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&& close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print |
|
|||
#!/usr/bin/perl /;{}def/#{def}def/$_={/Times-Bold exch selectfont}#/_{rmoveto}#/"{dup}#/*/!/$ ;/q{exch}#/x ; {/J q #}#/.{/T q #}#{stringwidth}#{}#{}# 14 string dup dup dup 260 40 moveto 90 rotate ; %/}};$0='"\e[7m \e[0m"';@ARGV=split//,reverse q(ThePerl). q(Journal) x 220 ; q ; 0 T putinterval exch 7 J putinterval ; ; $_= q /m$ pop T($*!$"=!$ " )pop " * true% ? $ " $!" " !! !! % !" !" ! ! charpath {!"""}pop $ pop{""!}pop ! neg{!#}pop 220 ! neg _{!!}pop J false %T charpath clip " pop 0 " moveto 6{!!}pop $_= 105{!!}pop {$ ! $ " ! #! ##} pop{dup dup $ ! " pop pop q{"}pop 22{dup show}repeat {"}pop q 22 mul{$ "} pop neg{!#! $ "}pop ! 8 .65 mul{$ # # $}pop ! neg{"}pop _ pop{"}pop } repeat pop " { $ " ! ! ! $ " ! !" "#" #"!"""""! #" " # "m/;@ARGV=(@ARGV[-14..-1])x50;q} 0 "%};s/m[ou]|[-\dA-ln-z.\n_{}]|\$_=//gx;s/(.)(?{$*=''})/('$*.='.(++$# %2?'':"$0;").'pop;')x(ord($1)-31).'$*'/gee;s/((.(\e\[.m)*|.){77})/$1\n/g;print ; sub showpage {} |
An example of a basic perl script:
|
|||
#!/usr/bin/perl # Name: Mark Tucker # Assignment: Lab01 Example #1 # Description: Basic "Hello World" program example. #========================================================================== # code goes here print "Hello World!\n"; # another comment exit; # not reuquired but a good idea. # DONE |
#!/usr/bin/perl
. The initial character pair
#!
tells the Unix shell that that this script will be
using it's own interpreter which is the executable program
that follows immediately, in this case
/usr/bin/perl
. The actual location of the perl
executable may vary depending on the version of Unix being
used. On Windows systems, this line is not necessary as
Windows uses the file name extension to determine how to run
the executable. It is still a good idea to include the line
in case the program is moved over to another type of system.
Under Unix based systems the file may be named any valid Unix
file name but it is helpful to name perl scripts with the .pl
extension so that they can easily be identified.
#
character. They
may be on a line by themselves or follow a perl statement.
Any text after the #
symbol is ignored by the
perl interpreter.
|
||||
tuckerm@apollo:~> tuckerm@apollo:~> perl zero.pl Hello World! tuckerm@apollo:~> |
perl
then reads the
contents of the file, compiles the script in system memory, and
executes the code.
|
||||
tuckerm@apollo:~> tuckerm@apollo:~> chmod a+x zero.pl tuckerm@apollo:~> tuckerm@apollo:~> ./zero.pl Hello World! tuckerm@apollo:~> |
chmod
command. It is then executed.
The Unix shell reads the first line "#!/usr/bin/perl"
and launches the perl interpreter to read the remainder of the
file. As in the previous example, perl
reads the
contents of the file, compiles the script in system memory, and
executes the code. For more information about the Unix
environment, check out the Unix course pages.
Scalar variables do not need to be "typed" as in C or other languages. Nor do they need to be declared before using them (although there are contexts in which it is very prudent to do so). Below are some examples of the behavior of variable assignment, subsitition and print statements.
Scalar variables in perl will always begin with the $
character. Array variables in list context will begin with the
@ character and hashes in list context will begin with the %
character. Variable names should not contain any
non-alphanumeric characters other than Perl's
"built-in" variables. Variables names should also not
have a numeric character at the beginning of the name. Perl
variable names are case-sensitive; ie. $fish
is a
different variable than $Fish
.
one.pl
|
|||
#!/usr/bin/perl # Name: Mark Tucker # Assignment: Lab01 Example #2 # Description: Basic "Hello World" program example modified to show variable # substitution and print behavior. #========================================================================== # code goes here $string = "Hello World!\n"; # another comment print STDOUT $string; # notice the escaping of the quotes. print "string is \"$string\""; # notices the single quotes and their behavior. print 'string is $string'; # assign a new value $string = 4; print $string; print "XX\n"; exit; # not reuquired but a good idea. # DONE |
two.pl
|
|||
#!/usr/bin/perl # Name: Mark Tucker # Assignment: Lab01 Example #3 # Description: Simple program to show the capture of STDIN # #========================================================================== # code goes here print "Please enter your name\n"; # get input from the user $name = <STDIN>; # strip any newline and carriage return characters with chomp chomp($name); # print variable back to stdout print STDOUT "Your name is $name\n"; exit; # DONE |
man perl - Perl overview. This is the main man page for Perl.
This document lists all the other man pages for perl available
on the system.
man perlfunc - Perl built-in functions
man perlre - Perl regular expressions
man perlfaq - Perl frequently asked questions
Many, many others...
last updated: 27 Aug 2015 12:42