Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: $1, etc. are not just strings

by ikegami (Pope)
on Jan 04, 2007 at 16:49 UTC ( #592985=note: print w/ replies, xml ) Need Help??


in reply to $1, etc. are not just strings

That reminds me of the danger of passing a var to a function that modifies that var. It's particularly easy to screw up when dealing with built-in globals variables such as $1.

sub func { 'b' =~ /(.)/; print(@_, "\n"); } 'a' =~ /(.)/; func($1); # Prints "b" 'a' =~ /(.)/; func("$1"); # Prints "a"
sub func { eval { die "bar\n" }; print(@_); } eval { die "foo\n" }; func($@); # Prints "bar" eval { die "foo\n" }; func("$@"); # Prints "foo"

(If you want to mess with your mind, try removing the second 'a' =~ /(.)/; from the first snippet.)


Comment on Re: $1, etc. are not just strings
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2015-07-06 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls