I have an app written in Perl/Tk. I am having a very strange problem in relation to the Button and Entry widgets. On one dialog I have an Entry widget and a Button. When the Button is pressed, I want to call a sub with the current contents of the Entry widget. Here is the code that attempts to do this:
my $newBtn =
$upper->Button('-text' => "New Subdirectory",
'-command' => [\&newDir, $direntry->get()])
->grid('-column' => 1,'-row' => 1);
This code successfully calls the newDir sub, but no value gets passed in. This led me to think that the
get() wasn't returning anything so I tried this line instead:
my $newBtn =
$upper->Button('-text' => "New Subdirectory",
'-command' => sub { print $direntry->get(),"\n"; })
->grid('-column' => 1,'-row' => 1);
Making this substitution prints out the correct information when the button is clicked.
Why can I only access the contents of the Entry through the anonymous sub? Why does it not seem to pass the value to the newDir sub? Is there some kind of scoping or execution order problem that I'm not aware of here? I'm sure I could wrap the call to newDir in an anonymous sub in the command handler, but the thought of doing that makes me cringe.
GuildensternNegaterd character class uber alles!