Hi all here's a tricky one I think;
First a code example using a Tk::Listbox;
my @list = (qw/1 2 3 4 5/);
$mw = MainWindow;
$list1 = $mw->Listbox->pack;
$list2 = $mw->Listbox->pack;
$but = $mw->Button(-text => 'Add',
-command => [\&ADD, $list1->curselection])->pack;
MainLoop;
sub ADD {
(my $index) = @_;
$list2->insert('end', $index);
}
What happens is $index is undefined.
if you change ADD to be;
sub ADD {
$list2->insert('end' $list1->curselection);
}
it all works tickety boo. So can anyone tell me why when the curselection method returns a scalar, I can't pass it as an argument to a function?
First a code example using a Tk::Listbox;
my @list = (qw/1 2 3 4 5/);
$mw = MainWindow;
$list1 = $mw->Listbox->pack;
$list2 = $mw->Listbox->pack;
$but = $mw->Button(-text => 'Add',
-command => [\&ADD, $list1->curselection])->pack;
MainLoop;
sub ADD {
(my $index) = @_;
$list2->insert('end', $index);
}
What happens is $index is undefined.
if you change ADD to be;
sub ADD {
$list2->insert('end' $list1->curselection);
}
it all works tickety boo. So can anyone tell me why when the curselection method returns a scalar, I can't pass it as an argument to a function?