




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Notes from the university of pittsburgh cs 1520 fall 2005 course on programming languages for web applications. Topics covered include running perl programs, lists/arrays with slices, push/pop, shift/unshift, sort/reverse, control structures such as if/then, while, until, do/while, input/output, and hashes. The document also introduces regular expressions.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Alexandros Lab rinidis, Univ. of Pittsb urgh 2 C S 1520 / Fall 2005
Use text editor (say pico) to write and save program, say hello.pl
perl -w hello.pl Next time: perl - w hello.pl
Make sure first line of hello.pl is the following #!/bin/perl -w chmod u+x hello.pl ./hello.pl Next time: ./hello.pl
Alexandros Lab rinidis, Univ. of Pittsb urgh^3 C S 1520 / Fall 2005
@beniffer = (“ben affleck”, “jennifer lopez”); $beniffer[1] = “jennifer gardner”; ($fred, $barney) = (14, 25); ($a, $b) = ($b, $a);
$a = @beniffer; print $a.”\n”; print @bennifer.”\n”; Alexandros Lab rinidis, Univ. of Pittsb urgh 4 C S 1520 / Fall 2005
Adds an element to end of list @list = (2, 4, 6); push @list, 5 ; # @list now (2, 4, 6, 5 ); Push @list, (3, 10); # @list now (2, 4, 6, 5, 3, 10);
Removes the last element of a list $p = pop @list; # $p becomes 10 # @list now (2, 4, 6, 5, 3);
Alexandros Lab rinidis, Univ. of Pittsb urgh^7 C S 1520 / Fall 2005
if ($a > 5) { #do nothing } else { $a++; }
Unless ($a>5) { $a++; } Alexandros Lab rinidis, Univ. of Pittsb urgh 8 C S 1520 / Fall 2005
while ($a > 5) { #do something }
until ($a <= 5) { $a++; }
Alexandros Lab rinidis, Univ. of Pittsb urgh^9 C S 1520 / Fall 2005
do { #do something } while ($a > 5);
do { #do something } until ($a <= 5); Alexandros Lab rinidis, Univ. of Pittsb urgh 10 C S 1520 / Fall 2005
print - simple printf - formatted version
standard input is accessed via
Alexandros Lab rinidis, Univ. of Pittsb urgh^13 C S 1520 / Fall 2005
return the list of current keys $fred{“a”} = “b”; $fred{“c”} = “d”; $fred(15) = 143; @list = keys(%fred); # @list = (“a”, “c”, 15); $n = keys(%fred); # $n = 3; foreach $k (keys (%fred)) { print “we have $fred{$k} at key $k\n”; }
Alexandros Lab rinidis, Univ. of Pittsb urgh 14 C S 1520 / Fall 2005
Iterate over all elements of hash hashname $lastname{“Alex”} = “Labrinidis”; $lastname{“Panos”} = “Chrysanthis”; $lastname{“John”} = “Ramirez”; while ( ($first, $last) = each (%lastname) ) { print “The last name of $first is $last\n”; }
delete $lastname{“Panos”};
Alexandros Lab rinidis, Univ. of Pittsb urgh^15 C S 1520 / Fall 2005