On 5/1/07, Somu <[EMAIL PROTECTED]> wrote:
Actually, that was just an example to explain my problem. I am facing
this problem when i use Tk. Any subroutine associated with the
-command option of a button widget.
use Tk;
my $mw = MainWindow->new;
my $b = $mw->Button(-text=>'hello',-command=>sub { &welcome })->pack;
my $l = $mw->Label(-text=>'')->pack;
sub welcome {
$l->configure(-text=>'welcome buddy'); }
MainLoop;
I have run this code on XP with ActivePerl 5.8.8.820 and had no
problems. Are you certain you are having problems with this exact
code? Also, the use of global variables will make your code
unmaintainable very quickly. You might wish to rewrite your code like
this instead:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new;
my $b = $mw->Button(-text=>'hello')->pack;
my $l = $mw->Label(-text=>'')->pack;
$b->configure(-command => sub { $l->configure(-text => 'welcome buddy') });
MainLoop;
or
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new;
my $b = $mw->Button(-text=>'hello')->pack;
my $l = $mw->Label(-text=>'')->pack;
$b->configure(-command => sub { welcome($l) });
MainLoop;
sub welcome {
my $label = shift;
$label->configure(-text => 'welcome buddy');
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/