Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Confused by variable scope in Tk::Wizard

by Anonymous Monk
on Apr 19, 2011 at 01:52 UTC ( [id://900036]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Confused by variable scope in Tk::Wizard
in thread Confused by variable scope in Tk::Wizard

Here is the exact same thing only written more verbosely
{ my $Aspirin = sub { return $wiz->_text_frame( { -title => 'Partitioning', -boxedtext => "/mirror/inifiles/partition.$oschoice", } ); }; $wiz->addPage($Aspirin); }
I suspect you're having trouble with closures

In my original program, this unnamed subroutine, this anonymous subroutine, whose reference is now stored in $Aspirin, refers to two variables outside its scope. Namely $oschoice and $wiz, which are not declared (my) within $Aspirin. This makes $Aspirin a closure.

Each time you call this subroutine, $Aspirin->(); it calls _text_frame with the current value of $oschoice

So if $oschoice="Lin" then $Aspirin->() returns a frame with /mirror/inifiles/partition.Lin

Next you change $oschoice="Win" and then $Aspirin->() returns a frame with /mirror/inifiles/partition.Win

The first step in the wizard edits $oschoice, then when you click next, the wizard invokes $Aspirin , which returns a new frame using the current value of $oschoice

If you click the back button and select a different OS, and click next again, the wizard will call $Aspirin again

More on closures, hopefully easier to understand :) oh and no wizards or witches :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found