Update: I've just had some people tell me that what happened to me does not happen on their machines. Until then, just treat this as another "Ain't life odd" kind of rambling story.

I'm just sharing an learning experience (screwup) that took me half an hour to track down - it was incredibly difficult to find. I literally got it down to a test case of about 20 characters and it still kept blowing up in my face. I was literally commenting out parts of an if statement.

I was using Parse::RecDescent to write (you guessed it), a parser, in which I had put the following code:

if ( ( $val =~ /m/i ) && ( $clamp =~ /y/i ) ) {......}

The parser was blowing up and reporting all sorts of odd errors. If you haven't spotted the error already, take a moment to see if you can spot it.






Here's the correct code:

if ( ( $val =~ m/m/i ) && ( $clamp =~ m/y/i ) ) {......}

Not only was the 'm' in the first conditional being interpreted as the start of a match, the 'y' in the second conditional was being treated as the transliteration operator. So I was copping it coming and going, so to speak.

And this was with strict and warnings switched on. Somehow the evals being used in Parse::RecDescent managed to miss the =~ / and treat the regex as an operator.

This is something I shan't miss in Perl6

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Implied operators are maddening
by blokhead (Monsignor) on Jun 04, 2003 at 06:03 UTC
    I don't think this is a problem with Perl's operators. The Perl interpreter (5.8 at least) gets this syntax right:
    $a = 'mmm'; $b = 'yyy'; if ( ( $a =~ /m/i ) && ( $b =~ /y/i ) ) { print "Hello\n"; } if ( ( $a =~ m/m/i ) && ( $b =~ m/y/i ) ) { print "Hello\n"; } __OUTPUT__ $ perl test.pl Hello Hello $ perl -MO=Deparse test.pl $a = 'mmm'; $b = 'yyy'; if ($a =~ /m/i and $b =~ /y/i) { print "Hello\n"; } if ($a =~ /m/i and $b =~ /y/i) { print "Hello\n"; }
    I wonder what P::RD could be doing with the code you give it to cause this. I'm not very familiar with the module, but that's just odd. Bug?

    FWIW, the regexes match correctly when I wrap them both in eval q{}'s. So eval doesn't seem to be a problem either.

    blokhead

      Yep, this is basically what people told me before I posted my update.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

Re: Implied operators are maddening
by edan (Curate) on Jun 04, 2003 at 14:26 UTC

    took me half an hour to track down - it was incredibly difficult to find

    I guess you are a much better code-debugger than I, because I would consider half an hour to find a bug a pretty good score! To me, 'incredibly difficult to find' is more like half a day, at least...

    --
    3dan