Here's a little info that will help you understand Perl/Tk programs:
Perl/Tk applications are event driven, which means that the program waits for "events" (keyboard, mouse, etc) and then executes accordingly. Event driven programs have a loop somewhere in them that catches and processes these "events". This is what
MainLoop in Tk is. It is simply a while loop that catches and processes events. Consequently, the code after
MainLoop never gets executed, unless it is
1) part of a sub that is called before
MainLoop executes or
2) part of a callback attached to a Tk widget.
This is why
print @a; never prints. To get it to print, put it in a sub that is part of a callback. Something like:
$mw->Button(-text => "print", -command=> sub {print @a })->pack;
or
$mw->Button(-text => "print", -command => \&print_it);
then somewhere below
MainLoop
sub print_it() {
print @a;
}
For a better explanation of Perl/Tk programming I would suggest that you get the book
Mastering Perl/Tk.
Hope this helps,
davidj