in reply to Please explain the '$x ||' idiom

Basically this reads set $x to 5 if $x is false (0 or undef)
$x = 0; $x = $x || 5; # prints 5 print $x; $x = 4; $x = $x || 5; $prints 4 print $x; $x = $x || 5; # prints 5 print $x;

Replies are listed 'Best First'.
Re^2: Please explain the '$x ||' idiom
by Fletch (Bishop) on Jan 18, 2005 at 18:28 UTC
    . . . $x is false (0 or undef)

    0 (but not "0 but true"), undef, or the empty string ""</nit>