Hi, Shlomi -
Thanks for the advice and the link. I appreciate it.
Webley

----- Original Message -----
From: Shlomi Fish <shlo...@shlomifish.org>
To: Webley Silvernail <webleysilvern...@yahoo.com>
Cc: Rob Dixon <rob.di...@gmx.com>; "beginners@perl.org" <beginners@perl.org>
Sent: Friday, February 24, 2012 12:36 PM
Subject: Re: Encoding angle brackets in HTML text nodes

Hi Webley,

On Thu, 23 Feb 2012 18:01:11 -0800 (PST)
Webley Silvernail <webleysilvern...@yahoo.com> wrote:

> --Snipped the previous posts as well as some of the redundant bits from 
> below.--
> 
> 
> >Hello Webley. See my comments below.
> >>snip
> >They are very different:
> >
> >  my $root = HTML::TreeBuilder->new_from_content($content)
> >
> >is the same as
> >
> >   my $root = HTML::TreeBuilder->new;
> >   $root->parse($content);
> >   $root->eof;
> >
> >and without parsing some sort of HTML to start with you are working with
> >an empty HTML tree.
> >>snip
> >
> >Unless you have parsed some HTML here your look_down will find nothing!
> 
> I was opening the file and passing it for parsing in separate steps like this:
> open IN, "$html_file" || die "Can't open input: $!";
> my $root = HTML::TreeBuilder->new;
> $root->parse_file(*IN);

Some notes about it:

1. You should use a lexical file handle instead of a glob:

« open my $in »

2. You should use the three-args open:

«open my $in, '<', $html_file.»

It is safer and better than the two-args open.

3. There's usually no need to write «"$html_file"» instead of just
«$html_file».

4. You probably want to surround the open in parentheses or use "or" instead of
"||".

For more information see:

http://perl-begin.org/tutorials/bad-elements/

Regards,

    Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

<rindolf>  If you repeat a scene 50k times, then the movie will have less 
entropy and will compress better. ( irc://irc.freenode.org/#perlcafe )

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to