in reply to Counting number of double quotes in a string

It's a problem with precedence:
friday:~ $ perl -MO=Deparse,-p -e '1 while $x = $y != $z' -e syntax OK '???' while ($x = ($y != $z));
As you can see, you're doing $pos = (index() != -1), where you want to do ($pos = index()) != -1. This problem causes $pos to be 1 all the time!

I have a better idea. Use the tr/// operator. $count += tr/"// while <FILE>;

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Counting number of double quotes in a string
by arajani (Novice) on May 13, 2002 at 16:54 UTC
    Hi Japhy,

    I realised the folly of not careful about the precedence.
    Thanks a lot and appreciate the help.

    Regards,

    Raj.