in reply to 'or' versus '||' - Unexpected Results

LIST: 0 | 3 = 3 (number of elements in the array)
LIST1: unlike ||, 'or' has a smaller priority than the assignment(=). So first 'my @list1 = x()' is executed, then if the it doesn't evaluate to true, '(1,2,3)' is evaluated and thrown away - this is the useless constant on line 14
I'm not sure what 2 and 3 do as I'm not familiar with Tk, but apparently bbox returns some value which prevents the rest from being evaluated.
  • Comment on Re: 'or' versus '||' - Unexpected Results

Replies are listed 'Best First'.
Re^2: 'or' versus '||' - Unexpected Results
by ikegami (Patriarch) on Jun 24, 2008 at 16:25 UTC

    LIST: 0 | 3 = 3 (number of elements in the array)

    That's wrong. For starters, there's no array involved. And before you say "I meant list", there's no list either involved either.

    Like I said in my post, "|" operates on scalars, so

    my @a = x() | (4,5,6);

    is evaluated as

    my @a = scalar(x()) | scalar(4,5,6);

    And keeping in mind that the comma operator returns it's RHS in scalar context,

    my @a = scalar(x()) | scalar(4,5,6); === my @a = scalar(x()) | scalar(5,6); === my @a = scalar(x()) | scalar(6); === my @a = scalar(x()) | 6;

    Perl doesn't even bother keeping the 4 and 5 in the compiled code:

    >perl -MO=Deparse -e"my @a = x() | (4,5,6);" my(@a) = x() | ('???', '???', 6);
      Thanks for the correction.