I'm trying to get a routine running as either a subroutine or more ideally an object(using strict and diagnostic). It works fine if it is all in the main body but once I put it in a subroutine It generates errors when trying to access the subroutine called from the "button Click" subroutine. So far I can't see any way round this. I have include an extract below. Thanks in advance.
my $Win = new Win32::GUI::Window( -left => 276, -top => 365, -width => 580, -height => 361, -name => "Win", -text => "Single Runner" ); my $Bad_Results = new Win32::GUI::Window( -left => 460, -top => 372, -width => 300, -height => 300, -name => "Results", -text => "Results" ); $Win->AddButton( -text => "Push Me!!", -name => "Button_1", -left => 200, -top => $Row, -width => 150, -height => 23, -foreground => 0, ); sub Button_1_Click { $Bad_Results->Show();} The eror message is of the following Variable "$Bad_Results" will not stay shared at rts_gui.pm line 435 (#1) (W closure) An inner (nested) named subroutine is referencing a lexical variable defined in an outer subroutine. When the inner subroutine is called, it will probably see the value of the outer subroutine's variable as it was before and during the *first* call to the outer subroutine; in this case, after the first call to the outer subroutine is complete, the inner and outer subroutines will no longer share a common value for the variable. In other words, the variable will no longer be shared. Furthermore, if the outer subroutine is anonymous and references a lexical variable outside itself, then the outer and inner subroutines will never share the given variable. This problem can usually be solved by making the inner subroutine anonymous, using the sub {} syntax. When inner anonymous subs that reference variables in outer subroutines are called or referenced, they are automatically rebound to the current values of such variables. _______________________________________________ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users