Hi all,
Are you ready for this one? :) Let's see if I can even explain what I'm
trying to do...
I'm attempting to dynamically create buttons that use the -onClick option to
go to a subroutine that is passed the name of the button. Why am I doing
this, you ask? Well, since I don't know the name of the button at the time
of its creation, I can't have an OEM event handler for it. Below is a code
snippet that might explain it better. The problem comes on line 7 when I try
to pass the name of the button (stored in $_ ) to the subroutine. I just
can't get $_ to persist when the subroutine is called later:
#############################################
foreach ( @button_names ) {
$main->AddButton(
-name => $_,
-size => [251,35],
-pos => [0,$y],
-text => $_,
-onClick => sub { Button_Clicked ( $_ ) },
);
++$y;
}
sub Button_Clicked {
print "Your name is " . $_;
}
#############################################
There just has to be a way to DWIM, but I've read perlsub over and over
again without figuring it out. How can I pass the name of the button to the
subroutine successfully?
Thanks,
Rob