The above code prints nothing."japhy" =~ /a/; eval q{ print $& };
The above code prints "ap"."japhy" =~ /a./; eval q{ print $& };
The above code prints "a"."japhy" =~ /a/; print $&;
Confused yet?
Here's the worst part:
That code prints "a".@& = (1,2,3); "japhy" =~ /a/; eval q{ print $& };
From the above examples, you should extract some things:
But if Perl sees you using $&, it makes everything that looks like a regex act like a regex, and set up the $& functionality. Bah. That's irritating, and "bad".
This just in: I patched gv.c so that only $& sets the PL_sawampersand flag to a true value. Now you can use @& without worry.
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Why Is $& Bad?
by tilly (Archbishop) on Sep 03, 2001 at 23:36 UTC |