Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Stumped with $_ being modified

by jdporter (Paladin)
on Jan 09, 2003 at 15:30 UTC ( [id://225556]=note: print w/replies, xml ) Need Help??


in reply to Re: Stumped with $_ being modified
in thread Stumped with $_ being modified

While tadman gives a perfectly fine solution, I'd pick a nit with certain of his advice:
Although using local will solve your problem, I'd stay away from it.

I'd really suggest steering away from using local declared variables.
That is really not good advice. local does not "declare" a variable, it localizes its value. This is a critically important capability -- as young_david's problem clearly demonstrates.
In many cases we don't have to worry about variables being localized, because the ops we use do it implicitly. (I'm thinking specifically of foreach.) But others, such as while, do not, and so we have to localize the variable explicitly -- if we want to be safe.

So rather than say "Don't use local", I'd say "use strict." That is a practice which will encourage good programming habits.

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found