Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Global vs. local?

by Corion (Patriarch)
on May 28, 2009 at 12:10 UTC ( [id://766638]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Global vs. local?
in thread Global vs. local?

You are not using strict, which would have enforced proper declaration of your lexical variables as lexicals:

sub execute_Click { another_sub(); foreach $j (0..$i-1) {

Here, $j is a global variable, which use strict; would tell you about. You need to write this as:

sub execute_Click { another_sub(); foreach $my j (0..$i-1) {

so that each subroutine gets its own copy of $j instead of them all using the one, shared $j.

strict also has the convenient feature of alerting you to mistyped variable names, which is why I recommend to use it always.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-24 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found