tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:
Button A prints the value of variable $var. Button '++' increments $var and Button '--' decrements $var. However if I first increment $var with '++' and then want to print its value with "Button A" the value of $var is 0 why is this? I guess I have missed something fundamental is it so? Thank you for your help.#!/usr/bin/perl -w + use Tk; use strict; my $mw = MainWindow->new; my $var=0; my $button_A = $mw->Button( -text => ' Button A', -command =>[\&rutine, $var, ]);# $button_A->pack; my $button_B = $mw->Button( -text => ' ++ ', -command => sub{$var++; print"\$var is $var!\n";}); $button_B->pack; my $button_C = $mw->Button( -text => ' -- ', -command => sub{$var--; print"\$var is $var!\n";}); $button_C->pack; MainLoop; sub rutine { my ($var)=@_; print "$var\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fundamental tk-problem
by liverpole (Monsignor) on Nov 13, 2006 at 15:17 UTC | |
by tamaguchi (Pilgrim) on Nov 13, 2006 at 16:19 UTC |