More fun with Deparse and the all too fleeting concept of special characters, giving further evidence that our character set is perhaps just not rich enough for Perl's liking ;-):
=== 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
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).

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


In reply to Re: Re^3: @ in regex, or not? by Albannach
in thread @ in regex, or not? by JPaul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.