LuBoB
LuBoB

Reputation: 1

Perl program for text work

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

Answers (2)

ikegami
ikegami

Reputation: 386551

I do spot numerous problems.

  1. if (//g) makes no sense and can cause actual (subtle) problems. Remove the g.
  2. You check eof() (twice!) without ever using <>. huh?
  3. You close file handle FILE, yet you never opened any such file handle.
  4. You close file handle FILE after checking if a different file handle has reached eof.
  5. You say your code doesn't do anything, yet you didn't bother to check if get returned something other than undef.

By the way, always use use strict; use warnings;. Not sure if you did or not.

Upvotes: 3

Nagaraju
Nagaraju

Reputation: 1875

You can use an XML module(XML::Parser) available over here It grabs the text between the tags.

Upvotes: 0

Related Questions