Why can't I create buttons in a for loop?

Does anyone know why the code posted below works out of a "for" loop but
does not work with the "for" loop?  I can execute the proggy fine with the
"for begin" and "for end" commented out, but not with them in.  Does anyone
have any suggestions?  I'm new to gtk but not necessarily perl.  For anyone
interested, my application is http://www.dashpc.com

Thanks very much in advance...!

#!/usr/bin/perl -w

use Gtk;         # load the Gtk-Perl module
use strict;      # a good idea for all non-trivial Perl scripts
set_locale Gtk;  # internationalize
init Gtk;        # initialize Gtk-Perl

my $window = new Gtk::Window( "toplevel" );
my $bw=5;

# callback registration
$window->signal_connect("delete_event", \&CloseAppWindow);
$window->border_width( $bw );

my @pornstar=("a","b","c","d","e","f","g","h","i","j");
my $i=0;
my @button=("1","2","3","4","5");

#doesn't work unless i comment the line below  and   ----------------!
for ($i=0;$i<5;$i++) {
  $button[$i] = new Gtk::Button("$pornstar[$i]");
  $button[$i]->signal_connect("clicked", \&CloseAppWindow);
#the line below also....  (basically, I can't do this in a loop,  whY?

main Gtk;

sub CloseAppWindow
   return 0;

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