gtk-perl bug, bad programming, or other?


I was creating a small Gtk app with perl and ran into what I think is a bug in gtk-perl.  Or am I just doing this wrong?. I was looping through an array to create a bunch of buttons and ran into weird problems using signal_connect.  I created a test case that creates six buttons to show this. I'm using Fedora linux 22 on intel with all updates. I also tested with both Gtk2 and Gtk3.

resulting output:

$ ./ 
get_label for button[0] is:  five 
get_label for button[1] is:  1 
get_label for button[2] is:  2 
get_label for button[three] is:  five 
get_label for button[four] is:  five 
get_label for button[five] is:  five 


$ cat 

use Gtk2 -init;

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

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

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

my @button;

$button[0]->signal_connect (clicked => sub {
   # Should output 0 , but does not
   print "get_label for button[0] is:  ".$button[0]->get_label." \n";

$button[1]->signal_connect (clicked => sub {
   # Should output 1
   print "get_label for button[1] is:  ".$button[1]->get_label." \n";

$button[2]->signal_connect (clicked => sub {
   # Should output 2
   print "get_label for button[2] is:  ".$button[2]->get_label." \n";

$button["three"]->signal_connect (clicked => sub {
   # Should output three , but does not
   print "get_label for button[three] is:  ".$button["three"]->get_label." \n";

# No quotes
$button[four]->signal_connect (clicked => sub {
   # Should output four , but does not
   print "get_label for button[four] is:  ".$button[four]->get_label." \n";

$button["five"]->signal_connect (clicked => sub {
   # Should output five
   print "get_label for button[five] is:  ".$button["five"]->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]