Perl Monk, Perl Meditation | |
PerlMonks |
Re^3: Confused by variable scope in Tk::Wizardby Anonymous Monk |
on Apr 19, 2011 at 01:52 UTC ( [id://900036]=note: print w/replies, xml ) | Need Help?? |
Here is the exact same thing only written more verbosely
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 :)
In Section
Seekers of Perl Wisdom
|
|