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);
In reply to Re: More efficient use of HTML::TokeParser::Simple
by liverpole
in thread More efficient use of HTML::TokeParser::Simple
by henka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |