in reply to Re^2: unexpected STDIN
in thread unexpected STDIN

My code is actually evaluating ('y' or 'yes') first, then comparing the (boolean) result (true since 'y' is not an empty string) to the value of $answer.

If I correctly understand this statement, I would make the following small, but important, clarification:

<quibble>
The expression
    ('y' or 'yes')
will always return 'y' specifically (rather than a 'canonical' true of 1) because the short-circuiting logical-or operator returns the value of the first operand that is true (or false if none is true). Thus
    (($answer eq 'y') or ($answer eq 'yes'))
(fully parenthesized) is probably certainly better than
    ($answer eq ('y' or 'yes'))
because the former will actually get around to evaluating  ($answer eq 'yes') someday if  $answer is not 'y'.
</quibble>

This may seem a mere, quibbling detail, but the Devil (and the 3 AM, tearing-your-hair-out debug session) is in the details.

Replies are listed 'Best First'.
Re^4: unexpected STDIN
by GhodMode (Pilgrim) on Apr 30, 2011 at 14:28 UTC

    +1 ... That's right.

    I got the exact effect of the misplaced parentheses wrong. It will actually work if the response is 'y' because that parenthesized expression will always yield 'y'.

    I might have gotten the reason for that effect right. Since 'or' is a logical operator, it evaluates the truth of the two operands. Since the first one is not an empty string, it's true, so the result of the expression is the first string, not just true like I originally stated.

    --
    Ghodmode
    www.ghodmode.com/blog