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

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

by rgcosma (Beadle)
on Apr 18, 2011 at 15:30 UTC ( [id://899961]=note: print w/replies, xml ) Need Help??


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

Thank you very much, the example does work. I do have to admit though that I don't understand why.. the syntax around this segment gives me a headache:
$wiz->addPage ( sub { $wiz->_text_frame( { -title => 'Partitioning', -boxedtext => "/mirror/inifiles/partition.$oschoice", } ); } );

Replies are listed 'Best First'.
Re^3: Confused by variable scope in Tk::Wizard
by Anonymous Monk on Apr 19, 2011 at 01:52 UTC
    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://899961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2026-02-07 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.