http://www.perlmonks.org?node_id=1130486


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);