On 11/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I'm playing around with references and wondered what this was:
>
> %a = {};

The right side of the assignment is a reference to an empty anonymous
hash. But you're assigning that (as a one-element list) to the hash
%a, which needs key-value *pairs*.

> %a seems to be a reference to nothing?

That can't be; %a is a hash, not a reference.

> A dump gives: ("HASH(0x18737e4)", undef)

That looks like the key was the reference (turned into a string) and
undef was used as the value. Some versions of Perl will give no
key-value pair at all when assigned a one-element list; if you have
warnings turned on, you should get a warning when you assign a single
element to a hash. Since the result of assigning an odd number of
elements to a hash is undependable, it's never a good way to write
Perl code.

In this case, because hash keys are strings, that line of code is
pretty-near useless; you can't turn the string back into the
reference. Did you find it in somebody else's code? If so, I'd give a
sceptical eye to the rest of their code. But something like this might
be good to use in the Obfuscated Perl Contest.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to