in reply to C-like Function Prototypes
in thread sub ($self,$var,@arr) {}

japhy writes:

$y ||= 10;

FWIW, be careful with that. Using ||= is one of my favorite ways to write fluent Perl, but it just got me burned a few days ago.

The problem was that the $y I was initializing was a numeric value - but zero was an acceptable value.

In that case, my ||= was overriding the supplied value of zero, which tested false against the operator. In the example here, providing an argument of 0 for $y will result in $y getting 10, not zero.

Oops. :-)

Peace,
-McD

Replies are listed 'Best First'.
Re: Careful...
by arturo (Vicar) on Feb 09, 2001 at 22:11 UTC

    #534987 in arturo's minor amplifications for the benefit of those who read the thread days later: For just those sorts of cases where false values are valid, $y =defined($y) ? $y : 10; (or whatever test makes sense).

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor