in reply to creating operands

No. That was actually one of the issues that perl 6 is supposed to address: the ability to add new operators. All we have today are existing operators and functions.

sub definedor { defined $_[0] ? $_[0] : $_[1] }
I think that's as good as you're going to be able to do before perl 5.9.2.

Of course, if you want a more generic one that can take multiple inputs, sort of emulating $a // $b // $c // ..., you could do:

sub definedor { use List::Util qw(first); first { defined } @_ }
and use it as definedor($a, $b, $c, ...) Of course, at this point, you almost may as well use the first function directly ;-)

Replies are listed 'Best First'.
Re^2: creating operands
by ikegami (Patriarch) on Jul 13, 2006 at 17:52 UTC

    That doesn't work here. Your solution eliminates short-circuiting. Short-circuiting is crucial here since we only want $self->error() to execute when the LHS is undefined. Without short-circuiting, $self->error() will be called unconditionally.

    Short-circuiting is not even a bonus in the provided snippet. The OP uses or/definedor exclusively for its short-circuiting properties, since the return value of the or/definedor is discarded.