http://qs321.pair.com?node_id=652365


in reply to Matching @ in string

perl -e 'if ("h@t" =~ /(\@)/ ) { print $1 }'
"h@t" looks to Perl like you're trying to interpolate the array @t (the previous case doesn't because the quote ends the string early.

perl -e 'if ("h\@t" =~ /(\@)/ ) { print $1 }'

or

perl -e 'if (\'h@t\' =~ /(\@)/ ) { print $1 }'

should work fine.

Update: err, ooops :-)

-David

Replies are listed 'Best First'.
Re^2: Matching @ in string
by dwu (Monk) on Nov 22, 2007 at 13:28 UTC

    *cough*

    $ perl -e 'if (\'h@t\' =~ /(\@)/ ) { print $1 }' -bash: syntax error near unexpected token `('

    Not sure why - does escaping the single quote not work?

      Because the bash does not change anything in the -e ' .. ' string. And
      if (\'h@t\' =~ /(\@)/ ) {
      is no valid perl.
      And the -e string ends after if (\.