[Templates] Re: How to separate between hash and array in data
returned from function
Mihai Bazon
mishoo@dynarch.com
Sun, 11 Feb 2007 15:29:31 +0200
Randal L. Schwartz wrote:
> Robin> I have a similar problem. My function has this return statement:
>
> Robin> my %hash=( one => 1, two => 2 );
> Robin> return wantarray ? %hash : \%hash;
>
> Robin> But when I try to access a member in the hash it fails.
>
> Right. For this, keep in mind that TT calls this function (if
> I understand correctly) *always* in a list context, so you'll
> get the key/value pairs. Ugh.
>
> If you always want a "TT Hash", you'll have to always return \%hash
> even in a list context.
>
Bottom line is, "wantarray" is dangerous... Unfortunately it's kind of
late to change my code now, but I learned the lesson. ;-)
Cheers,
-M.