[Melbourne-pm] Weirdness with references
Alfie John
alfiejohn at gmail.com
Wed Sep 6 19:02:09 PDT 2006
Thanks guys! I should have Dumper()'d it before hand.
Now another wierd thing I just found:
FAILS
print %{ {} }
WORKS
print %{ undef || {} }
Looks like Perl doesn't like balanced curlies without any surrounding fluff :)
Alfie
On 9/7/06, Scott Penrose <scottp at dd.com.au> wrote:
> Very odd...
>
> A quick note to anyone who tries this - it actually on dies if you
> "use strict";
>
> > my %empty;
> > print %{ $empty{'fake'} }
>
> Yep - makes sense, you can't use an undef or nothing as a hashref -
> must be a real hashref.
>
> > my %empty;
> > print values %{ $empty{'fake'} }
>
> Nope - makes no sense
>
> But here is my fav !
>
> THIS WORKS
>
> use warnings;
> use strict;
> my %empty;
> print values %{ $empty{'fake'} };
> print %{ $empty{'fake'} };
>
> THIS FAILS
>
> use warnings;
> use strict;
> my %empty;
> print %{ $empty{'fake'} };
> print values %{ $empty{'fake'} };
>
> so then try this...
>
> use warnings;
> use strict;
> use Data::Dumper;
> my %empty;
> print Dumper(\%empty);
> print values %{ $empty{'fake'} };
> print Dumper(\%empty);
> print %{ $empty{'fake'} };
>
> And you see what is happening !
>
> $VAR1 = {};
> $VAR1 = {
> 'fake' => {}
> };
>
> So the "values" sort of "forces" it to be a hashref - I guess that in
> that case it returns an lvalue or similar and as values must be on a
> hash it makes it so... maybe?
>
> Scott
> --
> * - * http://www.osdc.com.au - Open Source Developers Conference * - *
> Scott Penrose
> Anthropomorphic Personification Expert
> http://search.cpan.org/search?author=SCOTT
> scott at cpan.org
>
> Dismaimer: While every attempt has been made to make sure that this
> email only contains zeros and ones, there has been no effort made to
> guarantee the quantity or the order.
>
> Please do not send me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>
> Microsoft is not the answer. It's the question. And the answer is no.
>
>
>
More information about the Melbourne-pm
mailing list