in reply to Re^3: @ in regex, or not?
in thread @ in regex, or not?
My guess: In the first example, Perl has escaped the @ itself since it saw no array there, but in the second example, it saw an array, and accepted the syntax, but in evaluation it vanished. In the third case, Perl knows there is no @a array and barfs, telling be to be more specific, however if @a does exist (example 4), Perl proceeds, though perhaps not doing what the author intended - it concatenates all the elements of @a and matches against the resulting string (that I didn't expect).=== 1 === perl -MO=Deparse -e "$_='abc@de';print if(/[_@]/)" $_ = 'abc@de'; print $_ if /[_\@]/; -e syntax OK perl -e "$_='abc@de';print if(/[_@]/)" abc@de === 2 === perl -MO=Deparse -e "$_='abc@de';print if(/[@_]/)" $_ = 'abc@de'; print $_ if /[@_]/; -e syntax OK perl -e "$_='abc@de';print if(/[@_]/)" /[]/: unmatched [] in regexp at -e line 1. === 3 === perl -MO=Deparse -e "$_='abc@de';print if(/[_@a]/)" In string, @a now must be written as \@a at -e line 1, near "[_@a" -e had compilation errors. $_ = 'abc@de'; print $_ if /[_@a]/; === 4 === perl -e "@a[0]='z';@a[23]='oob';$_='abc@de';print if(/[_@a]/)" abc@de
Usually when I play around like this I learn something interesting, but as often as not I also end up with new questions!
--
I'd like to be able to assign to an luser
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: @ in regex, or not?
by tye (Sage) on Mar 28, 2001 at 05:11 UTC |