Re: gtk-perl bug, bad programming, or other?


On Wed, Jul 6, 2016 at 11:52 AM, Quentin Sculo <squentin free fr> wrote:
It seems you are confusing arrays and hashes.
In perl $button["five"] is the same as $button[0], as "five" is 0 when converted to a number.
That's why you should "use strict" for everything but one-liners.
Don't worry, we all do stupid mistakes :)

D'oh , thanks

Here is the code working:

get_label for button{one} is:  one 
get_label for button{two} is:  two 
get_label for button{three} is:  three 
get_label for button{quit} is:  quit 

$ cat 

use Gtk2 -init;
use strict; # <- IMPORTANT 

my $window = Gtk2::Window->new ("toplevel");

my $layout = Gtk2::Layout->new(undef,undef);
$window->add ($layout);

my $vbox = Gtk2::VBox->new();

my @buttons = qw( one two three quit);
my %button;

foreach my $row ( @buttons ) {
  $button{$row}->signal_connect (clicked => sub {
     print "get_label for button{$row} is:  ".$button{$row}->get_label." \n";


exit 0;


Christopher McCrory
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]