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

Re: Global vs. local?

by moritz (Cardinal)
on May 28, 2009 at 09:22 UTC ( [id://766612]=note: print w/replies, xml ) Need Help??


in reply to Global vs. local?

You can replace your entire switch/case with this code:
*$SUB = sub { variableMaxText($j); };

And you're done. This will create a closure, ie a subroutine that's "closed" over $j.

Replies are listed 'Best First'.
Re^2: Global vs. local?
by jpavel (Sexton) on May 28, 2009 at 09:39 UTC
    This is what I initially tried - makes sense to me. In the context of this sub function, "variableMaxText" always gets called with no value getting passed. If I declare $j globally, then the last value of $j gets passed every time (e.g., if I have 5 of them, the value is always "4" no matter which GUI element makes the call).
      See Corion's reply below: if you make a copy of that variable first (with my, not local, it should work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found