Keep It Simple, Stupid | |
PerlMonks |
Re^3: return value of chomp is false?by toolic (Bishop) |
on Sep 29, 2009 at 17:28 UTC ( [id://798166]=note: print w/replies, xml ) | Need Help?? |
Let me try to elaborate on my answer.
Firstly, here is a quote from the documentation for the Conditional Operator: Ternary "?:" is the conditional operator, just as in C. It works much like an if-then-else. If the argument before the ? is true, the argument before the : is returned, otherwise the argument after the : is returned. Coming from the STDIN handle, I agree that $_ will have a newline character. This means that chomp $_ will return 1. Since Perl treats 1 as a true value, the ternary operator will return the argument before the :. In your first case, chomp $_ ?"":$_, the ternary operator returns an empty string. In your second case, chomp $_ ?$_:"", the ternary operator returns $_.
In Section
Seekers of Perl Wisdom
|
|