[Melbourne-pm] Weirdness with references

Simon Taylor simon at unisolve.com.au
Wed Sep 6 18:33:16 PDT 2006


Hello Alfie,

> Could somebody please explain to me why the following die()s
>
>     my %empty;
>     print %{ $empty{'fake'} }
>
> Yet, the following doesn't
>
>     my %empty;
>     print values %{ $empty{'fake'} }
>
> I am thinking that values() flattens the given arguments in an eval?
> If it does, why?

Actually I think Perl is up to it's old auto-vivification tricks again.

If you look at the contents of $empty after your "print values ..." statement 
you'll see that the hash now has a 'fake' element. (At least it does for me 
at Perl 5.8.3).

Perhaps someone who knows more about Perl internals can offer an opinion?
I had thought that this no longer happened.

- Simon

P.S. If you want weird, try this:

my %hash;
$hash{print 2.0+3.1} = 'some value';
print $hash{print 2.0+3.1} . "\n";

One of my genetic algorithms bred this monstrosity the other day and I was 
delighted by the side effect..... ;-)







 

>
> Alfie
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm

-- 
Unisolve Pty Ltd - Melbourne, Australia
+61 3 9568 2005



More information about the Melbourne-pm mailing list