in reply to -w, strict, and Tk...

Hi Necos,

Just a quick suggestion (must run off). What I frequently do with Tk apps (and I write lots of them) is to create an anonymous hash to hold all the widgets that I might need to address elsewhere.. Then I can pass that hash around and avoid globals. For example (psuedo code):

my $w; $w->{main} = MainWindow->new; $w->{other_widgets} = $w->{main}->Label->.... # and then later... &subroutine($w); sub subroutine { my $w = shift; # Do stuff with $w here now like normal $w->{main}->configure( -title => "new title" ); }
My personal rule is that if I get the variable used only once warning then I've done something wrong with my design and implementation and I should rework my solution.

Update: demerphq makes a good point. To add to what is said there, I'd like to comment that there are lots of ways to reference a variable without context;

1 if $a; # for example
Another thing that I've done in the past when stuck with these kinds of warnings is to create a special subroutine just to reference them (assuming their global status):
sub unused { warn "sub unused was used!!!\n"; return; 1 if $a; 1 if $b; }
But I really feel that if you are in this situation you may wish to think carefully if there is a better way to accomplish what you are trying to do.

Again, good luck - {NULE} (/Update).

Final Update: Here is sample code that accomplishes what Necos wanted.

#! /usr/bin/perl -w use strict; use Tk; use Tk::Toplevel; ################ # Main Routine # ################ my $w; $w->{main} = MainWindow->new(-title => 'Tk Hash'); $w->{main}->Button(-text => "Click me to open a new toplevel", -comman +d => [ \&new_tl, $w ])->pack; $w->{main}->Button(-text => "Click me to test for other button", -comm +and => [ \&test_tl, $w ])->pack; MainLoop; exit; ############### # Subroutines # ############### sub new_tl { my $w = shift; if ( not Tk::Exists $w->{toplevel} ) { $w->{toplevel} = $w->{main}->Toplevel( -takefocus => 1, -title + => 'Top Level' ); $w->{testbutton} = $w->{toplevel}->Button(-text => 'Null butto +n'); } else { $w->{toplevel}->deiconify(); $w->{toplevel}->raise(); $w->{toplevel}->focusForce(); } } sub test_tl { my $w = shift; if ( Tk::Exists $w->{testbutton} ) { print "testbutton exists\n"; } else { print "testbutton does not exist\n"; } }

{NULE}
--
http://www.nule.org