Code Comments
Programming Forum and web based access to our favorite programming groups.More a perl question than a perl Tk question.
I tried
-command => [\&display, $filename, $namelength, %fet_choices]
with a widget; and the "display" function gets its arguments as :
my ($filename, $namelen, %fet_hash_ref) = @_;
but this doesn't work. There are no errors, but the "values" of the
local hash - within the function - are always zero. Any idea why?
This did work for me :
for the widget :
-command => [\&display, $filename, $namelength, \%fet_choices]
and "display" :
sub display(){
my ($filename, $namelen, $fet_hash_ref) = @_;
Using a reference worked without problems. Anyone with insight into
this, do educate me.
Thanks,
Ananth
Post Follow-up to this messageIn article <410FF993.3010000@prism.gatech.edu>, gtg563c@prism.gatech.edu says...
> More a perl question than a perl Tk question.
>
> I tried
> -command => [\&display, $filename, $namelength, %fet_choices]
>
> with a widget; and the "display" function gets its arguments as :
>
> my ($filename, $namelen, %fet_hash_ref) = @_;
>
> but this doesn't work. There are no errors, but the "values" of the
> local hash - within the function - are always zero. Any idea why?
Because %fet_choices is evaluated at the time the widget's
-command option is being evaluated, and the hash is probably
empty at that time. The following delays %fet_choices
evaluation until the -command option is invoked:
-command => sub{display($filename, $namelength, %fet_choices)}
> This did work for me :
>
> for the widget :
> -command => [\&display, $filename, $namelength, \%fet_choices]
>
> and "display" :
>
> sub display(){
> my ($filename, $namelen, $fet_hash_ref) = @_;
>
> Using a reference worked without problems. Anyone with insight into
> this, do educate me.
A reference to a hash is the same regardless of the hash's
contents. Each time display() is called, the current contents
of the hash are available via the reference.
--
Go to http://MarcDashevsky.com to send me e-mail.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.