1:23am
> > Unless otherwise directed, fill in the blank. > > ====================================================================== > | Sigils and data types | > ====================================================================== > > Sigil Variable type > ===== ============= > > $ _____________scalar > > @ _____________array > > % _____________hash > > & _____________not sure > > * _____________typeglob > > > > ====================================================================== > | Special variables | > ====================================================================== > > Briefly describe (less than 10 words) the use of these variables. > > $0 holds name of program > > $1, $2, $3... value of each () in last lexical regex > > @ARGV array containing command line arguments to program > > $ARGV current file if using <> to parse argv > > $_ default var > > @_ default array (in a sub) > > $! last error > > %ENV configuration and stuff > > > > ====================================================================== > | Quotes | > ====================================================================== > I'm not sure what to do here... > 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 calls function open > > 2. PW filehandle 'PW' > > 3. "/etc/passwd" filename > > 4. die exit on error > > 5. $! error message to output > > > ================ > > # Open file for input. > $data_file = "sales.ca"; > > open DATA, "<$data_file________________" or die "Cannot open input file: $!"; > > > > # Open file for output (truncate). > $out_file = "commisions.ca"; > > open OUT, ">$out_file________________" or die "Cannot open output file: $!"; > > > > # Open file for output (append). > $log_file = "status.log"; > > open LOG, ">$log_file________________" or die "Cannot open log file: $!"; > > > > # Open pipe for input to Perl. > $ps_cmd = "ps -au | grep msrw"; > > open PS, "dono..________________" 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, "dono...________________" or die "Cannot open printer pipe: $!"; > > > > ====================================================================== > | binary operators | > ====================================================================== > > operator string numeric > =========================================== > > equal to eq____ = _____ > > not equal to ne____ != _____ > > less than lt____ < _____ > > greater than gt ____ > _____ > > less than or equal to ?? ____ <= _____ > > greater than or equal to ?? ____ >= _____ > > comparison cmp____ <=> _____ > > > > ====================================================================== > | truth | > ====================================================================== > > Any value that is not false is true. What 3 values indicate > false? > > numeric -- 0 > > string -- '' > > other -- undef > > > > ====================================================================== > | shell interaction | > ====================================================================== > > Perl from shell > > 1. How is a perl program invoked from a shell (e.g. ksh, sh, bash)? > call it like an executable > > > Shell from Perl > `/bin/sh` > 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? > fork? > > > ====================================================================== > | hygeine | > ====================================================================== > > 1. How do you specify the -w flag inside a Perl file? > use warnings; > > > ====================================================================== > | 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); > > foreach my $lang ( @language ) { > 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 my $key ( keys (%aphorism) ) { > > my $value = $aphorism{$key}; > > print "$key...$value\n"; > > } > > > > ====================================================================== > | command line arguments | > ====================================================================== > > What do the following command line arguments mean? > > -w warning > > -e one-liner > > -i causes <> to direct output to the origional file > > -p -n use the loop while (<>) { } around your script, p has a continue, n dosen't > > > > ====================================================================== > | operators | > ====================================================================== > > Name that Perl operator: > > open________ open a file or pipe creating a filehandle > > close________ close a filehandle > > chomp________ chomp the trailing newline from a scalar string > that one was a bit obvious > $#arry________ determine the length (element count) of an array > > read()________ read (scalar or list) from a filehandle > > push________ add scalar(s) to right side (high index) end of array > > pop________ remove scalar(s) to right side (high index) end of array > > unshift________ add scalar(s) to left side (low index) end of array > > shift________ remove scalar(s) to left side (low index) end of array > > reverse()________ reverse a list > > sort()________ sort a list > > keys()________ extract a list of hash keys > this was covered in a previous question > values()________ extract a list of hash values > > delete $hash{$key}________ delete an element from a hash > > print________ print to a filehandle (STDOUT by default) > > printf________ print a formatted string to a filehandle (STDOUT by default) > > split('RE', $string) ________ split a string at RE into a list > > substr??________ join a list with a string into a string > > warn()________ warn user with message to STDERR > > die________ exit after warning user with message to STDERR > > return________ return from a subroutine or eval block > > system________ call the system > > > > ====================================================================== > | Regular Expressions | > ====================================================================== > > Supply the repetition quantifier for these convenience quantifiers: > > * {1,___} > > + {0__,___} > > ? {0__,1__} > > > Briefly describe (less than 5 words) these flags > > /i ignore case > > /g repeat > > /x prety-printed regex > > /o compile once > > > /====================================================================\ > | \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / | > |==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V== ==V==| > | / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ | > \====================================================================/ > 1:51 I'm just a little above intro to perl, but I still have a few million things to learn. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]