in reply to parsing HTML

tr returns the number of translations it has done - so you can use code like:

$count = $text =~ tr/"/"/;

to get the number of double quotes in $text.

I can't help wondering, however, why you're trying to reinvent HTML::Parser. What does that module not do that you need?

--
<http://www.dave.org.uk>

Perl Training in the UK <http://www.iterative-software.com>

Replies are listed 'Best First'.
Re: Re: parsing HTML
by eod (Acolyte) on Sep 14, 2001 at 15:30 UTC
    I reinvent the wheel (that's true :) ), this way I learn how to make one.
    Perhaps is a stupid idea, but I'm learning a lot about parsers and its problems and it's interesting.
    Anyway, the real reason is that I'm working in Windows with Savant Web Server, my version doesn't have any HTML libs.
    I like to run my application in any Web Server, and the parser I'm doing is a very simple one (not a complete HTML Parser). So I can permit this "re-invention".

    I knew the question was simple, but I really didn't know how to solve it. And you are great, Perl Monks.

    Thanks very much!!
    --edu
Re: Re: parsing HTML
by Rhandom (Curate) on Sep 14, 2001 at 20:00 UTC
    On a trivial note about counting occurances of letters you can do it all of these ways:

    my $txt = "1,2,3,4,5,6"; my $n1 = scalar(split(/,/,$txt))-1; my $n2 = scalar(@{[ split(/,/,$txt) ]})-1; my $n3 = scalar($#{[ split(/,/,$txt) ]})-1; my $n4 = (y/,/,/); my $n5 = (m/,/g);

    But the last is by far the fastest because it doesn't do any string modification. It's also the best for golf.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];