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

I would like to pass the results from the LWP::Simple's get() function to the HTML::TokeParser::Simple object using a string. Currently, I am writing to a file and then opening the file for the TokeParser.
Also I do not understand the reference to the $document scalar in the following HTML::TokeParser docs:

$p = HTML::TokeParser->new( \$document );

Replies are listed 'Best First'.
Re: How do I pass a string to HTML::TokeParser::Simple object?
by borisz (Canon) on Aug 13, 2004 at 07:43 UTC
    my $html = '<html><head><title>text</title></head><body>something</bod +y></html>'; $p = HTML::TokeParser->new( \$html );
    \$scalar is a reference to the scalar. Read perlreftut.
    Boris
Re: How do I pass a string to HTML::TokeParser::Simple object?
by revdiablo (Prior) on Aug 13, 2004 at 08:58 UTC

    To create a scalar reference without actually saving the contents to a variable first, you could try something like the following:

    $p = HTML::TokeParser->new( \(get $url) );

    It's kind of a hack, and a bit ugly, but the choice is yours.

Re: How do I pass a string to HTML::TokeParser::Simple object?
by Ovid (Cardinal) on Apr 26, 2005 at 16:55 UTC

    It's a bit late in the game, but in case someone stumbles across this, I'd like to mention that the latest HTML::TokeParser::Simple allows you to do this:

      my $parser = HTML::TokeParser::Simple->new(url => $url);

    It relies on LWP::Simple, so it will croak if that is not installed.

    Cheers,
    Ovid

    New address of my CGI Course.