Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Matching @ in string

by dwu (Monk)
on Nov 22, 2007 at 13:24 UTC ( [id://652364]=note: print w/replies, xml ) Need Help??


in reply to Matching @ in string

I'm suspecting because perl interprets @t within the string h@t as the array @t, since double quotes ("") will cause variables to be interpolated. Inserting both tests into a short script:

#!/usr/bin/perl use strict; use warnings; if ("h@" =~ /(\@)/ ) { print $1 } if ("h@t" =~ /(\@)/ ) { print $1 }

produces:

Possible unintended interpolation of @t in string at ./scratch.pl line + 6. Global symbol "@t" requires explicit package name at ./scratch.pl line + 6. Execution of ./scratch.pl aborted due to compilation errors.

Doing:

#!/usr/bin/perl use strict; use warnings; if ('h@' =~ /(\@)/ ) { print $1 } if ('h@t' =~ /(\@)/ ) { print $1 }

produces:

@@

As expected. HTH.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found