"The three principal virtues of a programmer are Laziness, Impatience, and Hubris." -- Larry Wall (Perl designer)
From the preface to Programming Perl: "Perl is a language for getting your job done."
Read the Perl readme to learn how to run a Perl script. Refer to this basic introduction to Perl while doing this lab. Ignore information on regular expressions, OO, and Perl modules. Refer to the first few pages of this Perl data reference for help on Perl's three built-in data types: scalars, arrays and associative arrays (hashes). Both sets of documentation can be accessed from the command line with:
man perlintro man perldataEverything you need to know to complete this lab is in test.perl, spell_check.perl and regex.perl. Copy the files into your working directory so you can test the code:
$ cp /home/fac/melissa/public_html/cs350-f15/examples/week05/spell_check.perl . $ cp /home/fac/melissa/public_html/cs350-f15/examples/week05/dictionary . $ cp /home/fac/melissa/public_html/cs350-f15/examples/week05/test.perl . $ cp /home/fac/melissa/public_html/cs350-f15/examples/week05/regex.perl .
Perl uses automatic, dynamic duck-typing. If Perl sees a number when it expects a string, it implicitly converts the number into a string; e.g. 25 becomes "25". If Perl sees a string when it expects a number, it implicitly converts the string into an arbitrary number; e.g. "hello" becomes 0. Data variables are prefaced with a sigil to denote structure: '$' scalar, '@' array, '%' hash. In an assignment the sigil used must match the lvalue type.
Your job is to write a Perl script to process this list of lines. Each line is in this form:
658,daffy,0,0,1,0,1,1,0,1,1,1In each line the first field is ID. The second field is name. The last 10 fields are the results from a quiz where '1' denotes correct and '0' denotes incorrect. Copy the datafile into your working directory:
cp /home/fac/melissa/public_html/cs350-f15/examples/week05/data .The usage of your script is:
lab05.perl [-h] -f <infile> -o <outfile>
SPECIFICATIONS:
Hint: for your regex to filter the sorted array you can anchor the regex at the beginning of the line using '^'; e.g. /^..[a-z]/ matches any line where the 3rd character is in the set of lowercase letters.
HOW YOUR LAB WILL BE GRADED
The perl script for this lab must reside here:
/home/stu/{username}/cs350/lab05/lab05.perlSample run:
$ ./lab05.perl -h Usage: lab05.perl [-h] -f <infile> -o <outfile> $ ./lab05.perl -f data -o log Lines read: 32 Enter an ID to query: 123 123 is greasy $ cat log Lines Sorted by ID and Filtered by ID with 2nd Digit >= 7 174,bambi,0,1,1,0,1,0,0,1,1,0 578,flotsam,1,1,0,1,1,1,1,1,1,0 688,hugo,0,0,1,0,0,1,0,0,1,0 799,genie,0,1,1,0,0,1,1,0,1,1 887,piglet,0,1,1,0,0,1,1,0,1,1 985,jetsam,1,0,1,0,0,0,0,1,1,1 Correct Counts: #1: 5 #2: 21 #3: 31 #4: 5 #5: 13 #6: 21 #7: 19 #8: 9 #9: 27 #10: 19 Question most frequently answered correctly: #3