Help me with a \"simpel\" perl program!
Could somebody help me with the following questions?I prefer English answers but it is also okay with Danish answers.
Consider the enclosed PERL program, webcollect4.pl:
a. Describe exactly what command line arguments
webcollect4.pl takes.
#!/usr/bin/perl
# webcollect4.pl
#
$location = $ARGV[0];
$level = $ARGV[1];
if (!$level) { exit;}
print STDERR \"*** page: $location level $level\\n\";
@contents = `/usr/bin/lynx -source $location`;
foreach $line (@contents) {
$newloc = \"\";
# http href
if ($line =~ m/href=\\\"?(http:[^\\>\\s\\\"]+)/i) {
$newloc = $1;
# href starting with ./ (local file)
} elsif ($line =~ m/href=\\\"?[.]\\/([^\\>\\s\\\"]+)/i) {
$newloc = \"$location/$1\";
# href starting with local file name
} elsif ($line =~ m/href=\\\"?([^\\>\\s\\\"]+)/i) {
$newloc = \"$location/$1\";
# html file for example with frames
} elsif ($line =~ m/=\\\"?([^\\>\\s\\\"]+html?)/i) {
$newloc = \"$location/$1\";
}
if ($newloc =~ /\\.(pdf|ps)/) {
print STDERR \"avoiding file $newloc\\n\";
} elsif ($newloc =~ /mailto\\:/) {
print STDERR \"avoiding file $newloc\\n\";
} elsif ($newloc) {
$newlevel = $level-1;
system(\"webcollect4.pl $newloc $newlevel\");
}
}
print @contents;
------------------------------------------------------
b. Consider the regular expressions in the following
two lines:
if ($line =~ m/href=\\\"?(http:[^\\>\\s\\\"]+)/i) {
elsif ($line =~ m/href=\\\"?[.]\\/([^\\>\\s\\\"]+)/i) {
For each of these regular expressions:
-Describe exactly what it matches
-Give a line that would match it