Please send questions to
st10@humboldt.edu .
#!/usr/bin/perl -w
#######################################################
# lab04_grab_names
#
# practice =~, binding operator, to check a given
# variable for a pattern; use the $' automatic
# match variable to then grab what FOLLOWS that
# pattern.
#
# modified by Sharon Tuttle from "Learning Perl",
# by Schartz and Phoenix
#
# last modified: 9-16-04
#######################################################
# ask for a file name to check for course-required marker
print "enter a file name to check: ";
chomp($file = <STDIN>);
# kluge to quick'n'sleazily read from this file...
$ARGV[0] = $file;
while (<>)
{
chomp($line = $_);
if ($line =~ /###480-author:/)
{
# automatic match variable $' grabs what FOLLOWED
# the latest successful match;
$authorname = $';
# let's strip any additional whitespace;
$authorname =~ s/\s+//g;
print "file has a script by: <$authorname>\n";
# make author name all caps...
$authorname =~ s/(.*)/\U$1/;
print "all uppercase?: $authorname\n";
# make author name all lowercase...
$authorname =~ s/(.*)/\L$1/;
print "all lowercase?: $authorname\n";
# make author name back to mixed case
$authorname =~ s/(.*)/\u\L$1/;
print "mixed case?: $authorname\n";
}
if ($line =~ /###480-scriptname:/)
{
# automatic match variable $' grabs what FOLLOWED
# the latest successful match;
$scriptname = $';
# let's remove any whitespace;
$scriptname =~ s/\s+//g;
print "file should contain a script: <$scriptname>\n";
}
}
# just to play... using case shifting for variables in a
# double-quoted string
print "at end of script, final script was \U$scriptname \Eby",
" \U$authorname\n";
print " (although they typed it in as $scriptname)\n";
# end of lab04_grab_names