I'd like a few volunteers to take a test that I've put together for an "Introduction to Perl" class that I teach. If you are a beginner or recent "graduate" of an intro course and have a few minutes, would you time yourself taking this test and send me the results?
================================================================ I don't usually give quizes at the end of class, but a client of mine has requested it. (Required it in fact. No test, no payment!) Because I don't want the test to be a bother at the end of the course, I've created my own objectives for the test: The final test for "Introduction to Perl" * will reinforce that the students have covered and practiced the objectives; * will allow students to demonstrate their mastery of introductory skills (rather than the deviousness of a seasoned instructor); * will serve as a concise review of course hilights; * will stimulate final in-class "fill-in" questions; * will uncover areas that are weak, or have been quickly forgotten, to focus personal study; * remind students of how much they learned in class; * convince students that their time investment created value for them, their group, and their company. The test I created is appended below. Please write down your start time and completion time and post it as a follow-up to this message or email me a reply with a self-assesment for your level relative to an "Introduction to Perl" class. Thank you very much for your assistance, Michael Wolf /====================================================================\ | \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / | |==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V==| | / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ | \====================================================================/ Unless otherwise directed, fill in the blank. ====================================================================== | Sigils and data types | ====================================================================== Sigil Variable type ===== ============= $ _____________ @ _____________ % _____________ & _____________ * _____________ ====================================================================== | Special variables | ====================================================================== Briefly describe (less than 10 words) the use of these variables. $0 $1, $2, $3... @ARGV $ARGV $_ @_ $! %ENV ====================================================================== | Quotes | ====================================================================== Syntactic Sugar Meaning Generic Interpolates ================================================================ ____ Literal q// No ____ Literal qq/ Yes ____ External command execution qx// Yes Word list generation qw// No RE match m// Yes RE substitution s/// Yes Character translation tr/// No RE quote qr// Yes ====================================================================== | open operator | ====================================================================== Here is a Perl common idiom that requires a sucessful file handle creation before continuing. open PW, "/etc/passwd" or die "Cannot open password file: $!"; Briefly (less than 5 words) describe its parts. 1. open 2. PW 3. "/etc/passwd" 4. die 5. $! ================ # Open file for input. $data_file = "sales.ca"; open DATA, "________________" or die "Cannot open input file: $!"; # Open file for output (truncate). $out_file = "commisions.ca"; open OUT, "________________" or die "Cannot open output file: $!"; # Open file for output (append). $log_file = "status.log"; open LOG, "________________" or die "Cannot open log file: $!"; # Open pipe for input to Perl. $ps_cmd = "ps -au | grep msrw"; open PS, "________________" or die "Cannot open status pipe: $!"; # Open pipe for output from Perl. $lp_cmd = "nl | pr -l60 -h'my report' | lp -d pr1"; open LP, "________________" or die "Cannot open printer pipe: $!"; ====================================================================== | binary operators | ====================================================================== operator string numeric =========================================== equal to ____ _____ not equal to ____ _____ less than ____ _____ greater than ____ _____ less than or equal to ____ _____ greater than or equal to ____ _____ comparison ____ _____ ====================================================================== | truth | ====================================================================== Any value that is not false is true. What 3 values indicate false? numeric -- string -- other -- ====================================================================== | shell interaction | ====================================================================== Perl from shell 1. How is a perl program invoked from a shell (e.g. ksh, sh, bash)? Shell from Perl 1. What *quotes* are used to invoke a shell (or other executable) from Perl, collecting its STDOUT? 2. What *operator* is used to invoke a shell (or other executable) from Perl, using the same STDOUT as Perl? ====================================================================== | hygeine | ====================================================================== 1. How do you specify the -w flag inside a Perl file? ====================================================================== | Array iteration | ====================================================================== This code illustrates a c-style loop, using $i as an index variable. my $i; my @language = qw(Perl C VisualBasic KornShell FORTH); for ($i = 0; $i < @language; $i++) { my $lang = $language[$i]; print "I can program in $lang.\n"; } Create a similar loop without using $i, in a more Perlish style. my @language = qw(Perl VisualBasic KornShell FORTH); ___________________________________ { print "I can program in $lang.\n"; } ====================================================================== | Hash iteration | ====================================================================== %aphorism = ( roses => red, violets => purple, sugar => "sweet, like maple syrple" ); Fill in the missing pieces to iterate over the hash. ==> The first blank will set $key to each of the keys of the hash (e.g. roses, violets, sugar). ==> The second blank will set $value appropriately. foreach ________________________________ { _______________________; print "$key...$value\n"; } ====================================================================== | command line arguments | ====================================================================== What do the following command line arguments mean? -w -e -i -p -n ====================================================================== | operators | ====================================================================== Name that Perl operator: ________ open a file or pipe creating a filehandle ________ close a filehandle ________ chomp the trailing newline from a scalar string ________ determine the length (element count) of an array ________ read (scalar or list) from a filehandle ________ add scalar(s) to right side (high index) end of array ________ remove scalar(s) to right side (high index) end of array ________ add scalar(s) to left side (low index) end of array ________ remove scalar(s) to left side (low index) end of array ________ reverse a list ________ sort a list ________ extract a list of hash keys ________ extract a list of hash values ________ delete an element from a hash ________ print to a filehandle (STDOUT by default) ________ print a formatted string to a filehandle (STDOUT by default) ________ split a string at RE into a list ________ join a list with a string into a string ________ warn user with message to STDERR ________ exit after warning user with message to STDERR ________ return from a subroutine or eval block ________ call the system ====================================================================== | Regular Expressions | ====================================================================== Supply the repetition quantifier for these convenience quantifiers: * {___,___} + {___,___} ? {___,___} Briefly describe (less than 5 words) these flags /i /g /x /o /====================================================================\ | \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / | |==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V==| | / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ | \====================================================================/ -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]