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

You are having an issue with Operator Precedence and Associativity. The || binds more tightly than the assignment operator, so you are assigning the return value of the print to $o. What you have is equivalent to

my $o = ( mysub() || print STDERR "didn't work\n" );

You can get your exected result either with explicit parentheses

(my $o = mysub() ) || print STDERR "didn't work\n";

or by swapping to the lower precedence or

my $o = mysub() or print STDERR "didn't work\n";

See Logical or, Defined or, and Exclusive Or in perlop.

Replies are listed 'Best First'.
Re^2: Returned value from subroutine is 1 when returning ""
by fidesachates (Monk) on Jan 06, 2011 at 16:23 UTC
    Thanks for the links.