[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Concise idiom sought



 <Tim Kazner> wrote in comp.lang.perl.misc:
> On 29 Mar 2006 07:29:50 GMT, anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno
> Siegel) wrote:
> > <Tim Kazner> wrote in comp.lang.perl.misc:
> >> On Mon, 27 Mar 2006 09:05:37 +0200, "Dr.Ruud"
> <rvtol+news@xxxxxxxxxxxx> wrote:
> >> >Randal L. Schwartz schreef:
> >> >
> >> >>         defined $_ or $_ = 1 for $base_ref->{pl};

[...]

> use strict;
> use warnings;
> 
> my ($base_ref,$v) = ({});
> 
> $$v=1 if ($v=\$base_ref->{pl} and !defined $$v);
> print "$$v\n";
>  
> ($base_ref,$v) = ({pl=>8});
> 
> $$v=1 if ($v=\$base_ref->{pl} and !defined $$v);
> print "$$v\n";
> 
> __END__
> 1
> 8

What is the advantage over

   defined or $_ = 1 for $base_ref->{pl};

Especially considering that $v is undeclared.  That would also have
to be done somewhere.

> Not really sure why this won't work:
> 
> $$v=1 if (!defined $($v=\$base_ref->{pl}));

That fails because de-referencing doesn't take an arbitrary expression.
You must give it a simple variable or a block:

    $$v=1 unless defined ${ $v=\$base_ref->{pl} };

Again, what is the possible advantage?

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.




Home | Main Index | Thread Index 7982 8225 25521 34506 38909 43037 51615 58494

9/9/2010 10:20:14 GMT