Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: This is really a Perl BUG with my?! Need some advice...

by chromatic (Archbishop)
on Jan 24, 2004 at 09:08 UTC ( [id://323807]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: This is really a Perl BUG with my?! Need some advice...
in thread This is really a Perl BUG with my?! Need some advice...

What would you expect this code to do?

if ($foo) { my $bar = 1; } print $bar;

You're doing the same thing without changing scope. Sometimes you ask Perl to create a new lexical in the pad, sometimes you don't. Since the sub reuses its pad between invocations and since destroying and recreating all lexicals in a pad is an expensive operation, if the my doesn't fire, you end up reusing the previous variable.

Update: Highlighted the important bit that I'd already explained.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://323807]
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 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found