Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

passing hashes to functions
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


Report this thread to moderator Post Follow-up to this message
Old Post
Ananth Chellappa
08-04-04 01:56 AM


Re: passing hashes to functions
In 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Marc Dashevsky
08-04-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.