Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Treating sub output as a hash

by AnomalousMonk (Abbot)
on Jan 26, 2012 at 17:26 UTC ( #950174=note: print w/ replies, xml ) Need Help??


in reply to Treating sub output as a hash

With 5.14, one can use keys, values and each directly on an unblessed hash (or array) reference or an expression that evaluates as such (although this is flagged as "highly experimental"). I don't have 5.14 and so cannot provide a working example, but I think it should go something like this:

for my $k (keys function_returning_hash_ref()) { print "the hash has a key $k \n"; } sub function_returning_hash_ref { return { fee => 'Fie', foe => 'Fum', }; }

Update: Example tested OK with 5.14 per chromatic (with thanks!).


Comment on Re: Treating sub output as a hash
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2015-07-05 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls