in reply to Returned value from subroutine is 1 when returning ""

The empty string evaluates to false in a boolean context, so the first value stored in $o is the return value of the print.

Replies are listed 'Best First'.
Re^2: Returned value from subroutine is 1 when returning ""
by fidesachates (Monk) on Jan 06, 2011 at 16:21 UTC
    Oh I understand now. I seem to have misunderstood the ||.

    I read the code as (my $o = mysub()) || print ...

    I see now that the grouping is my $o = (mysub() || print ...

    Thank you.

      When in doubt about what exactly the precedence will be, B::Deparse is your friend.

      $ perl -MO=Deparse,-b,-p -e 'my $o = mysub() || print STDERR "WHY U NO + WORK\n";' (my $o = (mysub() || print(STDERR "didnt work\n")));

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.