[Linux-disciples] perl question: why do modules return a reference to a hash and not a hash?

Stephen R Laniel steve at laniels.org
Thu Dec 22 14:06:45 EST 2005


Looking through the camel book just now, I found this:
http://www.unix.org.ua/orelly/perl/prog3/ch06_03.htm

"If you want to pass more than one array or hash into or out
of a function, and you want them to maintain their
integrity, then you'll need to use an explicit
pass-by-reference mechanism. Before you do that, you need to
understand references as detailed in Chapter 8,
"References". This section may not make much sense to you
otherwise. But hey, you can always look at the pictures...

Here are a few simple examples. First, let's define a
function that expects a reference to an array. When the
array is large, it's much faster to pass it in as a single
reference than a long list of values: "

And so on. So I think speed -- the fact that Perl doesn't
have to make a copy of every object you're passing in as an
argument -- is one big reason, and list integrity is
another.

I'd imagine that the speed/memory-usage argument is
especially strong for database stuff, where the objects
you're passing around are routinely enormous.

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20051222/e14cd8a3/attachment.pgp


More information about the Linux-disciples mailing list