in reply to regular expression with @@/

Your code is fine. Both \Q and \ will escape @.

$ perl -le'print q{@@} =~ m|\A\Q@@\E\z| ? "match" : "no match"' match $ perl -le'print q{@@} =~ m|\A\@\@\z| ? "match" : "no match"' match

Are you sure your input is what you think it is?

Update: Turns out that \Q only helps insofar as @@ doesn't get interpolated to begin with.

Replies are listed 'Best First'.
Re^2: regular expression with @@/
by almut (Canon) on Dec 07, 2009 at 19:22 UTC
    Both \Q and \ will escape @

    No, \Q doesn't:

    $ perl -wle'print q{@@x} =~ m|\A\Q@@x\E\z| ? "match" : "no match"' Possible unintended interpolation of @x in string at -e line 1. Name "main::x" used only once: possible typo at -e line 1. no match $ perl -wle'print q{@@x} =~ m|\A@\@x\z| ? "match" : "no match"' match
      ah, interesting!
      $ perl -le'@@=qw( a b ); print qr|\Q@@|' (?-xism:\@\@) $ perl -le'@@=qw( a b ); print qr|@@|' (?-xism:@@) $ perl -le'@a=qw( a b ); print qr|\Q@a|' (?-xism:a\ b)

      I knew something was hinky with what I had posted.