Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: More efficient use of HTML::TokeParser::Simple

by liverpole (Monsignor)
on Jul 10, 2006 at 20:05 UTC ( [id://560210]=note: print w/replies, xml ) Need Help??


in reply to More efficient use of HTML::TokeParser::Simple

Hi henka,

I hadn't used HTML::TokeParser::Simple before, but I just tried it now, and it works fine for me even after removing the second call:

my $p = HTML::TokeParser::Simple->new($ARGV[0]);

So it seems logical that you would only instantiate the object once at the beginning.

(Update:  Whoops ... not necessarily the case, as several wiser monks have gently instructed below.)

A couple of points I'd mention, though.  First, if you add:

use strict; use warnings;

at the beginning of your code, you'll see that you've redefined $p.  (The strict and warnings pragmas are considered good programming practice, as they will catch a lot of things that might otherwise cause you problems -- it's a good idea to use them in all your programs).

Secondly, it might be more helpful to the user (or even yourself!) if you give an error message or a syntax message in case no argument are passed to the program.  For example:

use HTML::TokeParser::Simple; (my $url = shift) or die "syntax: html_test <filename>\n"; my $p = HTML::TokeParser::Simple->new($url);

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: More efficient use of HTML::TokeParser::Simple
by bart (Canon) on Jul 10, 2006 at 20:41 UTC
    I hadn't used HTML::TokeParser::Simple before, but I just tried it now, and it works fine for me even after removing the second call:
    my $p = HTML::TokeParser::Simple->new($ARGV[0]);
    Only if all the tags your want to capture next, come below the first one ("title"). It's very likely they do.

    Can you rewind a HTML::TokeParser::Simple? I don't think you can. But you can go through the tags one at a time, and check if it's one you're interested in, be it "title" or "h1". I wish it provided a way to scan for any of ("title", "h1"). Perhaps it will in the future, I think I'm going to supply a patch to that effect.

Re^2: More efficient use of HTML::TokeParser::Simple
by henka (Novice) on Jul 11, 2006 at 06:11 UTC
    Thanks liverpole - I always use strict/warnings - this was just a copy/paste of a test script.

Log In?
Username:
Password:

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

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

      No recent polls found