in reply to Effecient shortcut for ?:

I don't believe efficiency comes into play, but, your 2nd example "could" be rewritten as
$foo = defined $bar ? bar : $default_for_foo; ## could be written as, but remember, that 0 is false $foo = $bar; $foo ||= $default_for_foo;

____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Effecient shortcut for ?:
by thelenm (Vicar) on Aug 07, 2002 at 18:23 UTC
    These two are not exactly the same... they will behave differently if $bar is defined but has a non-true value (like 0). That's because the || operator tests for truth, while the much-to-be-desired // operator (in Perl6) will test for defined-ness. So in Perl6, you could write it as:
    $foo = $bar; $foo //= $default_for_foo;
    or, I imagine, like this:
    $foo = $bar // $default_for_foo;

    -- Mike

    --
    just,my${.02}