Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

or

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

should work fine.

Update: err, ooops :-)

-David


Comment on Re: Matching @ in string
Select or Download Code
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 (\.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-12-17 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (32 votes), past polls