wirrwarr has asked for the wisdom of the Perl Monks concerning the following question:
now I'd like to apply the internal perl function keys to this function. I triedsub func { return ('a' => 'ah', 'b' => 'be') };
all of which give the following error:keys func(); keys ( func() ); keys ( &func() );
It works if I use a temporary variable though:Type of arg 1 to keys must be hash (not subroutine entry)
Now is there a way I can use the function directly? Or doesn't Perl's syntax allow this? perldoc perlfunc gives following description:my %hash = func(); keys %hash;
Returns a list consisting of all the keys of the named hash. ...which seems to imply I have to use a variable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Apply function "keys" directly to function returning hash
by benn (Vicar) on Aug 25, 2003 at 16:48 UTC | |
|
Re: Apply function "keys" directly to function returning hash
by herveus (Prior) on Aug 25, 2003 at 16:50 UTC | |
by wirrwarr (Monk) on Aug 25, 2003 at 16:56 UTC | |
|
Re: Apply function "keys" directly to function returning hash
by sgifford (Prior) on Aug 25, 2003 at 19:19 UTC | |
by wirrwarr (Monk) on Aug 26, 2003 at 10:35 UTC | |
by sgifford (Prior) on Aug 26, 2003 at 18:07 UTC |