in reply to Worrying regex issue with 5.8.0

This is some weird stuff, but I'm confused. Does the name of the variable ($re_bad) imply that expression typed by the programmer is bad, or are you saying that this should be considered an okay expression, and perl just seems to be doing something bad to it?

I wonder, because this part:  [A-Z$#@_#] seems to be specifying "#" twice within a character class, which seems odd (should be harmless, granted, but odd). The "qr" operator is being used with single-quote delimiters, so the "@_" is being taken literally, rather than being interpolated (was that your intention?). When some other delimiter is used, the result is different: with nothing else in the script, "@_" is empty, so it seems to interpolate as an empty string in this case.

I tried both ways, on both my home linux and my office solaris 5.8, and got results that were not identical, but equivalent, and worrisome in all cases. Feeding Data::Dumper's output through something like "od" helps to see the issue:

solaris5.8 $ test.perl | od -t ax1 0000000 $ V A R 1 sp = sp q r / ( ? x - +i 24 56 41 52 31 20 3d 20 71 72 2f 28 3f 78 2d +69 0000020 s m : @ @ ( [ A - Z $ # @ _ # +] 73 6d 3a 40 40 28 5b 41 2d 5a 24 23 40 5f 23 +5d 0000040 * ) sp ( ? ! sp [ A - Z a - z 0 +- 2a 29 20 28 3f 21 20 5b 41 2d 5a 61 2d 7a 30 +2d 0000060 9 $ # @ _ ] sp ) nul nul lf ) / ; lf 39 24 23 40 5f 5d 20 29 00 00 0a 29 2f 3b 0a
Note the null bytes. Is it supposed do that? I happened to get the exact same results on linux for this case.

Now, if I change the delimiters on "qr" to something else (like slashes), which allows the "@_" to interpolate, the two systems do seem to differ:

solaris5.8 $ test-slashes.perl | od -t ax1 0000000 $ V A R 1 sp = sp q r / ( ? x - +i 24 56 41 52 31 20 3d 20 71 72 2f 28 3f 78 2d +69 0000020 s m : @ @ ( [ A - Z # ] * ) sp +( 73 6d 3a 40 40 28 5b 41 2d 5a 23 5d 2a 29 20 +28 0000040 ? ! sp [ A - Z a - z 0 - 9 $ # +@ 3f 21 20 5b 41 2d 5a 61 2d 7a 30 2d 39 24 23 +40 0000060 _ ] sp ) can lf ) / ; lf 5f 5d 20 29 18 0a 29 2f 3b 0a ##### linux2.4 $ test-slashes.perl | od -t ax1 0000000 $ V A R 1 sp = sp q r / ( ? x - +i 24 56 41 52 31 20 3d 20 71 72 2f 28 3f 78 2d +69 0000020 s m : @ @ ( [ A - Z # ] * ) sp +( 73 6d 3a 40 40 28 5b 41 2d 5a 23 5d 2a 29 20 +28 0000040 ? ! sp [ A - Z a - z 0 - 9 $ # +@ 3f 21 20 5b 41 2d 5a 61 2d 7a 30 2d 39 24 23 +40 0000060 _ ] sp ) s lf ) / ; lf 5f 5d 20 29 73 0a 29 2f 3b 0a
Where solaris had one garbage character (0x18), linux had a different character ("s"), which on the surface looks plausible, but is garbage nonetheless, I expect (e.g. it's whatever happens to have been at some point in core when a C function happens to step past the boundary of an array).

Also, it seems that only the first instance of "@_" was interpolated -- if that makes sense, I need to read perlre again, much more carefully...

Replies are listed 'Best First'.
Re: Re: Worrying regex issue with 5.8.0
by ruscoekm (Monk) on Nov 15, 2002 at 08:21 UTC

    I am glad that somebody managed to repeat the error. I think that people were beginning to think I was seeing things :-)

    I want to try some more tests myself but, to answer your questions:

    The variable name $re_bad is meant to imply that Perl is doing something bad with a valid regex. The regex is meaningless, that was just as small as I could get it. (As mentioned above, if I remove any further elements, I do not get the error.) The real regex is much longer. In fact, I got this error for a couple of regexes - one to match a SQL label and one to match a SQL global variable.

    Yes, I intentionally used single quote delimeters. I have also observed the behaviour when using other delimeters. However, so far, I only get the problem when using /x...

    Kevin