Rugular expressions? Help!
Hvis der er nogen der kan klare det følgende, vil jeg blive meget glad for et svar:)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:
a.Describe exactly what it matches
b. Give a line that would match it
Jeg tror man også skal bruge dette program til at løse det:
#!/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;