SPUG: Slice of HashOfHash

Jacinta Richardson jarich at perltraining.com.au
Mon Nov 20 05:36:15 PST 2006


DeRykus, Charles E wrote:
>  
> 
>>> Ivan Heffner wrote:
>>> Use Perl's short-circuiting logical '||'
>>> to make a single method call (or set of method calls):
>>>
>>>   foreach my $family ( $cartoon->families() ) {
>>>       if ( ( $cartoon->$family->husband() || '' ) eq 'fred') {
>>>            print "yes\n";
>>>       }
>>>   }
> 
>> Or even:
>>  ( $cartoon->$family->husband() // '' ) eq 'fred'
> 
> Did you perhaps mean  the proposed ?? (hook-hook operator) 
> rather than  // ... ? 

I suspect he means dor (//): defined or.  In 5.10 you'll be able to write:

	$a //= 0;

which will be the same as writing:

	$a = ( defined $a ? $a : 0);

I don't believe this is available in the 5.8 branch, but it's there for some of 
the 5.9 bleedperls.  The English version of this will be "dor" (and possibly 
"err" as well) and like "or" will have a lower precedence than //.

Of course, we need to wait until 5.10 first and some of this will require
"use feature qw(...)";

What's "??" ?

	J


More information about the spug-list mailing list