[lug] Perl/Tk question.

David Stepaniak davestep at cgd.ucar.edu
Mon Jun 30 15:13:54 MDT 2003


Dear BLUGer's:

I have been tinkering with the following short Perl/Tk script:



#!/usr/sbin/perl -w

  use Tk;

  $mw = MainWindow->new;
  $mw->title('Entry Widget');

   $mw->Label(         -text => 'Enter some characters:'
             )
       ->pack;

   $mw->Entry( -textvariable => \$input,
             )
       ->pack;

  $mw->Button(         -text => 'Send input to standard out',
                    -command => [ \&printInput, $input ]
             )
       ->pack;

  $mw->Button(         -text => 'Exit',
                    -command => sub{ exit; }
             )
       ->pack(         -side => 'bottom' );


  MainLoop;



  sub printInput {

    print "The user supplied input is $_[0]\n";

  }



No matter what I do, the argument $_[0] in sub printInput is
undefined:

Use of uninitialized value at entryWidget.pl line 31.

which results in an incomplete standard out of

The user supplied input is



In sub printInput, if $_[0] is replaced by $input, things
work as expected. Am I overlooking the nature of the scope
of $input, especially in the entry widget, and then in relation to
the first button widget (with the reference to the printInput
subroutine in the callback)?


Thank you for any insight.


David Stepaniak




More information about the LUG mailing list