File Opening, Input, Output and Sorting

File Handles open (FILE_HANDLE, “”); Open for reading: open (SONGS, “song_list.txt”); open (SONGS, “song_list.txt”) or die “Can’t open that file! Error is $!”;   Retrieve lines using < > : open (SONGS, “song_list.txt”) or die “Can’t open that file!”; for $line (<SONGS>) { print $line; }   Open for overwriting: open (SONGS, “>song_list.txt”) or die …

Perl String Comparisons and String Replacements

Strings and String Comparisons Be careful which operators you use! Are you assigning, or testing? $answer = “no”;if ($answer == “yes”) {print “Answer is Yes.\n”;} Exercise: do test operatiors make a difference? Test this code: $i = 11;if ($i == “11”) { print “Equivalent numbers.\n”; }if ($i eq “11”) { print “Equivalent strings.\n”; } Getting …

Perl “if” Testing

if: Testing a Condition if ($user eq “fred”) {print “Welcome in, Fred.\n”;}elsif ($user eq “joe” || $user eq “jill”){print “Get out, $user\!\n”;}else {print “No Admittance.\n”;} unless ($age > 21 && $smile == “big”) {print “You’re too young for me.\n”;}else {print “How about a date?\n”; } Note the “and” ( && ) and “or” ( || …

Perl Operators

Operators The ever-friendly explanation: The more formal Perlop re. Operators Compare Perl vs. Shell Operators:

Perl Functions

Functions print ( ) print “You can print a single string like this one.\n”; print “Or you can “, “supply a list “, “of strings separated by commas.”; Resources