Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Returning Hash from subroutine of form 'var' => 1,

by kroach (Pilgrim)
on Jun 15, 2015 at 15:03 UTC ( #1130486=note: print w/replies, xml ) Need Help??


in reply to Returning Hash from subroutine of form 'var' => 1,

Could you please provide more context (the assignment and use of the returned value and a full working example)?

The return itself seems fine. The following code works:

use strict; use warnings; use Data::Dumper; sub ret_hash { return nick => 1; } my %hash = ret_hash(); print Dumper(\%hash);

Perhaps you are trying to return a hash reference. If you assign the function result to a scalar you should return a reference. Anonymous hashes can be created with {}:

use strict; use warnings; use Data::Dumper; sub ret_hash { return {nick => 1}; } my $hash = ret_hash(); print Dumper($hash);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2020-10-23 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (238 votes). Check out past polls.

    Notices?