[Templates] Re: How to separate between hash and array in data returned from function
Randal L. Schwartz
merlyn@stonehenge.com
Sat, 10 Feb 2007 22:17:36 -0800
>>>>> "Robin" =3D=3D Robin Smidsr=F8d <robin@smidsrod.no> writes:
Robin> Randal L. Schwartz wrote:
>> If I recall, you can return an arrayref, which will always be interprete=
ed
>> correctly as an "array" in TT-side. So, returning [] will correctly
>> be seen as "size of 0" and [42] will be seen as "size of 1", etc.
>>=20
Robin> I have a similar problem. My function has this return statement:
Robin> my %hash=3D( one =3D> 1, two =3D> 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.
--=20
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl trainin=
g!