Reputation: 1
I am writing a script in Perl, but Im just a beginner. This program downloads html page and tries to find phrases bounded by tags. I attached a code below, when I check it, there's no errors but it does nothing (no print out). So please can anybody give me some advice what can be wrong?
open ':std', ':encoding(UTF-8)';
my $s = get("xxx.html");
foreach my $line (split(/\n/,$s)) {
if (m,<>(.*?)<>,g) {
if(eof()) {
close(FILE); }
print "$1\n";
last if eof();
}
}
Upvotes: 0
Views: 128
Reputation: 386551
I do spot numerous problems.
if (//g)
makes no sense and can cause actual (subtle) problems. Remove the g
.eof()
(twice!) without ever using <>
. huh?FILE
, yet you never opened any such file handle.FILE
after checking if a different file handle has reached eof.get
returned something other than undef.By the way, always use use strict; use warnings;
. Not sure if you did or not.
Upvotes: 3