in reply to Return value from function
So often, I let the user decide, and base my return value on wantarray: If a sub is called in scalar context, I return a ref, but in list context, I return a flat list.
Call as either of:sub foo { my %hash = ( a => 1, b => 2 ); return wantarray ? %hash : \%hash; }
ormy $hashref = foo();
my %hash = foo();
|
|---|