[Linux-disciples] perl question: why do modules return a reference
to a hash and not a hash?
Adam Rosi-Kessel
adam at rosi-kessel.org
Thu Dec 22 13:33:55 EST 2005
Stephen R Laniel wrote:
> and func1() and func2() both return lists, Perl will treat
> the arguments as a single long list. Then in the
> implementation of someFunc, you want to treat them as two
> separate lists, and you can't: by the time someFunc sees the
> arguments, they're collapsed into one list.
[...]
> If the DBI functions returned raw objects, you'd have to
> make references out of them anyway to use them inside other
> functions, then dereference them inside the other functions.
This is also a pretty good explanation, although I don't think it applies to
hashes. Whether a hash is returned, or a pointer to a hash is returned, it's
still just one item. I.e.:
someFunc( someOtherFunc(), yetAnotherFunc() )
If someOtherFunc() and yetAnotherFunc() both return arrays, as I understand
your point, then someFunc() will not actually get two arrays but just a big
list and not know the dividing point between the two arrays. Thus, you would
rather have them both return pointers to arrays so that someFunc() is just
called with two parameters, rather than however many elements there are in
the combined arrays.
If someOtherFunc() returns a hash, however, then it will be a unitary item,
regardless of whether it is a hash, or a reference to hash.
No?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 250 bytes
Desc: OpenPGP digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20051222/23edd516/signature.pgp
More information about the Linux-disciples
mailing list