in reply to Re: Did I match or didn't I?
in thread Did I match or didn't I?

re: "The two OR operators actually behave quite differently"

That is a whole new issue, since perlop says, "It's equivalent to || except for the very low precedence."

What are the differences? And lets let the doc pumpking know.

Updated: The precidence is indeed the only difference. The "as previously noted"

my ($result) = m[pattern(group)] or "default";
is not correct.

Replies are listed 'Best First'.
Re: Re: Re: Did I match or didn't I?
by chipmunk (Parson) on Oct 18, 2001 at 20:17 UTC
    The only difference between or and || is precedence. || has high precedence; or has low precedence.

      my @list = func_returning_list() || 'default'; This is parsed as my @list = (func_returning_list() || 'default');, which fails because || forces func_returning_list() into scalar context.   my @list = func_returning_list() or 'default'; This is parsed as (my @list = func_returning_list()) or 'default';, which fails because 'default' is not assigned to @list when func_returning_list() returns an empty list.

    Using ?: is the right solution.

    In perl6, the logic operators will allow their context to propagate to both their operands, so the first snippet will work as intended.