l.frankline has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am working with a text file, it contains xml tags consisting of huge lines.

what i have done in the code is...I find opening tag "<bul-list>" and keep counting it in a variable $bullopen and closing "</bul-list>" in a variable $bullclose

This code is working fine but, but I need a better code than this... I mean it in a shortest code. Can any help me.

$bullopen = 0; $bullclose = 0; while ($_=~s#<bul-list>##) { $bullopen++; } while ($_=~s#</bul-list>##) { $bullclose++; } print $bullopen; print $bullclose;

Thank u in advance
Franklin
Don't put off till tomorrow, what you can do today.

jpodrter fixed code tags

Replies are listed 'Best First'.
Re: Any other options for total count
by Samy_rio (Vicar) on Nov 16, 2005 at 12:34 UTC

    Hi, Try this,

    $bullopen = $_ =~ s/<bul-list>//g; $bullclose = $_ =~ s/<\/bul-list>//g;

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Re: Any other options for total count
by dorward (Curate) on Nov 16, 2005 at 12:36 UTC

    What are you actually trying to do? Are you trying to check for well formedness?

    Why are you not using one of the many XML handling modules on CPAN?

Re: Any other options for total count
by Perl Mouse (Chaplain) on Nov 16, 2005 at 13:23 UTC
    Shortest doesn't always equal "better".

    Anyway, here's some shorter code:

    print+(()=/<bul-list>/g).(()=/<\/bul-list>/g);
    Perl --((8:>*