Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: "$_" vs. $_

by Brovnik (Hermit)
on Apr 11, 2007 at 11:44 UTC ( #609349=note: print w/ replies, xml ) Need Help??


in reply to "$_" vs. $_

I think this is what you wanted :

#!/usr/bin/perl use strict; use warnings; sub foo { my %params = @_; print "$_: $params{$_}\n", for keys %params; } my $word = shift @ARGV || "world"; foo ( hello => $word );
Do not use $_ as a temporary variable unless essential.

Declaring and naming the variable catches a lot of issues and solves (for example) the problem you came across as well as improving readability.


Comment on Re: "$_" vs. $_
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2015-07-04 16:09 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 (60 votes), past polls