Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

RE: Re: redeclaring variables with 'my'

by extremely (Priest)
on Nov 11, 2000 at 03:16 UTC ( [id://41050]=note: print w/replies, xml ) Need Help??


in reply to Re: redeclaring variables with 'my'
in thread redeclaring variables with 'my'

You are correct Fastolfe, the re-allocation happens in the loop. However, this is the behavior that is GOOD. The cost of the allocation is a great deal less than this
my $x='ok'; # scads of code my $x=300; while ($x--) { do_something_with($x); } # scads of code... print "$final" if ($x eq 'ok'); #kaboom

In the end, when you do a "-w" and it complains that '$x won't stay shared' or something at the second my, your lesser perl wizard is likely to take the "my" off since the variable is already declared. Ouch.

In the end, you suffer the cost of extra work on the backside to protect yourself from the future.

--
$you = new YOU;
honk() if $you->love(perl)

Log In?
Username:
Password:

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

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

    No recent polls found