[Melbourne-pm] Weirdness with references

leif.eriksen at hpa.com.au leif.eriksen at hpa.com.au
Wed Sep 6 19:29:21 PDT 2006


Another valuable debugging tool is the B::Deparse module - to see what Perl internally parsed your code to be. In this case however, all it gives is a bigger headache.


le6303 at hpa-3a0cc069587 ~
$ perl -MO=Deparse -e 'print %{ { } }'
print %{{};};
-e syntax OK

le6303 at hpa-3a0cc069587 ~
$

Note I had to add a space between the inner hash ref - else it’s a compile error !? But if you type in what Deparse returns, it still a syntax error !

le6303 at hpa-3a0cc069587 ~
$ perl -MO=Deparse -e 'print %{{ }}'
print %{{};};
-e syntax OK

le6303 at hpa-3a0cc069587 ~
$ perl -MO=Deparse -e 'print %{{};};'
Unmatched right curly bracket at -e line 1, at end of line
syntax error at -e line 1, near ";}"
-e had compilation errors.

Weird.

L

-----Original Message-----
From: alfiejohn at gmail.com [mailto:alfiejohn at gmail.com] 
Sent: Thursday, 7 September 2006 12:02 PM
To: scottp at dd.com.au
Cc: melbourne-pm at pm.org
Subject: Re: [Melbourne-pm] Weirdness with references

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.
>
>
>
_______________________________________________
Melbourne-pm mailing list
Melbourne-pm at pm.org
http://mail.pm.org/mailman/listinfo/melbourne-pm

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.1/440 - Release Date: 6/09/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.1/440 - Release Date: 6/09/2006
 
**********************************************************************
IMPORTANT
The contents of this e-mail and its attachments are confidential and intended
solely for the use of the individual or entity to whom they are addressed.  If
you received this e-mail in error, please notify the HPA Postmaster, postmaster at hpa.com.au,
then delete  the e-mail.
This footnote also confirms that this e-mail message has been swept for the
presence of computer viruses by Ironport. Before opening or using any
attachments, check them for viruses and defects.
Our liability is limited to resupplying any affected attachments.
HPA collects personal information to provide and market our services. For more
information about use, disclosure and access see our Privacy Policy at
www.hpa.com.au
**********************************************************************


More information about the Melbourne-pm mailing list