Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

LWP and TokeParser

by silent11 (Vicar)
on Jan 11, 2002 at 02:16 UTC ( [id://137847]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://137847]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found