silent11 has asked for the wisdom of the Perl Monks concerning the following question:

Why doesn't this code work? I am very new to OOP, so if there is something wrong with my logic someone please point it out. Thanks.
use HTML::TokeParser; use LWP::Simple; $get = get('http://perlmonks.com'); $file = HTML::TokeParser->new("$get"); while ( $token = $file->get_tag("a")) { my $url = $token->[1]{href} || "-"; my $text = $p->get_trimmed_text("/a"); print "<a href=$url>$text</a><br>"; }

Replies are listed 'Best First'.
Re: LWP and TokeParser
by redsquirrel (Hermit) on Jan 11, 2002 at 02:31 UTC
    Where is $p coming from? You never defined it.
      Sorry, it should be :
      use HTML::TokeParser; use LWP::Simple; my $stuff = get('http://some_url.com); my $file = HTML::TokeParser->new("$stuff"); while ( my $token = $file->get_tag("a")) { my $url = $token->[1]{href} || "-"; my $text = $file->get_trimmed_text("/a"); print "<a href=$url>$text</a><br>"; }

      And why can't I edit my original post as I usually can ??
      oh well, thanks in advance!
        Re-read `perldoc HTML::TokeParser`. you want HTML::TokeParser->new(\$stuff).
Re: LWP and TokeParser
by lshatzer (Friar) on Apr 09, 2002 at 01:03 UTC
Re: LWP and TokeParser
by BazB (Priest) on Jan 11, 2002 at 16:29 UTC

    I just want to utter the Perlmonk matra: Use strict warnings and diagnostics or die.

    Another thing that will help you is spacing out and indenting your code - especially conditional loops such as your while loop.