[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 13:52:59 EST 2005
On Thu, Dec 22, 2005 at 01:46:41PM -0500, Adam Rosi-Kessel wrote:
> sub HashFunction {
> my %hash = { 'a' => 1, 'b' => 2};
> return %hash
> }
[snip]
> So apparently in the first example (where dereferenced variables are
> returned), the function called gets *three* parameters, although the second
> one is empty (?). In the second example (where references are returned),
> only two variables are passed to CheckFunction, which is probably the
> expected/desired behavior.
It worked the way it worked because you didn't define the
hash the right way:
my %hash = { stuff };
creates an anonymous *function*, not an anonymous hash. You
meant to do
my %hash = ( 'a' => 1, 'b' =>2 );
Again, the syntax for initializing hashes is the same as
that for initializing lists. I'm pretty sure that if you
rerun your function-that-calls-other-functions with a hash
as an argument, you'll get the output you expect.
--
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/767d082a/attachment.pgp
More information about the Linux-disciples
mailing list