Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Matching @ in string

by erroneousBollock (Curate)
on Nov 22, 2007 at 13:24 UTC ( #652365=note: print w/ replies, xml ) Need Help??

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 }'


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

should work fine.

Update: err, ooops :-)


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


    $ 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 (\.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://652365]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2016-04-30 03:36 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.