70 likes | 205 Views
Running a Perl Program. #!/usr/bin/perl5.00404 print(“Howdy, world!<br>”); # comment Make sure the file is executable: chmod +x howdy.pl ./howdy.pl. Online help. perldoc perl (overview) perldoc perlfaq (freq. asked questions) perldoc perldata (data structures)
E N D
Running a Perl Program #!/usr/bin/perl5.00404 print(“Howdy, world!\n”); # comment Make sure the file is executable: chmod +x howdy.pl ./howdy.pl CSE 341 - S. Tanimoto Perl -
Online help perldoc perl (overview) perldoc perlfaq (freq. asked questions) perldoc perldata (data structures) perldoc perlsyn (syntax) perldoc perlop (operators and precedence) perldoc perlre (regular expressions) perldoc perlrun (execution and options) etc. (see Schilli, p.3) CSE 341 - S. Tanimoto Perl -
Data Types $n = 25; # a numeric scalar $str = “Here is a string”; print(‘The value of $n is ‘ . $n); # Note strings with ‘ ‘ do not have # variable “interpolation performed” # But strings with “ “ DO have it. print(“The value is $n.”); CSE 341 - S. Tanimoto Perl -
String Operations “string1” . “string2” # concatenation Can also be done using interpolation: $str1 = “abc”; $str2 = “def”; $newstr = “$str1$str2”; CSE 341 - S. Tanimoto Perl -
Immediate (“Here”) Documents print <<“END-OF-PRINT”; Hello there. This is a two-line immediate text doc. END-OF-PRINT $mytext = <<TextEnd This is some text that ends on a blank line TextEnd CSE 341 - S. Tanimoto Perl -
Arrays @trees = (“Oak”, “Maple”, “Madrona”); @moretrees = qw(pine alter hemlock); @ages = (75, 50.5, “twenty); $mytree = $trees[1]; # “Maple” CSE 341 - S. Tanimoto Perl -
Hashes (Associative Arrays) $foodtype{‘Spaghetti’} = ‘Italian’; $thetype = $foodtype{‘Spaghetti’}; foreach $food (keys %foodtype) { $thetype = $foodtype{$food}; print “Food $food is $thetype\n”; } CSE 341 - S. Tanimoto Perl -