[tpm] Is there a three-way version of...

Shaun Fryer sfryer at sourcery.ca
Sat May 30 12:49:50 PDT 2009

Thanks Guys,

>        foo() ;
>        foo( undef ) ;


> #       $self->{foo} = shift if @_ ;

I like that one. Short and sweet. The reason I was looking for a more
compact version is I find myself also often doing this kind of
evaluation on one or another type of nested reference. For instance.

    $$aref[$i][$j][$k] = $$href{foo}{bar}{baz} if defined $$href{foo}{bar}{baz};

Hopefully it's clear the merits of being able to do the following instead.

    $$aref[$i][$j][$k] =// $$href{foo}{bar}{baz};

Perhaps I'm just being [too] lazy. Or a new trick for Perl 6...

Anyway, next question...

Seeing you do "@array > 1" made me wonder about a particular style
issue. In the past I've done just that, but recently have started
explicitly doing "scalar(@array) > 0" alot more often (by default).
It's been my understanding that the "$#array" idiom is deprecated. If
there are arguments for/against each of the above, what are they?
Maybe I'm making a mountain out of a molehill for nothing...?

Shaun Fryer

More information about the toronto-pm mailing list