in reply to Re^4: how to read STDIN interactively
in thread how to read STDIN interactively
The undef being returned isn't the value of $/, it's a signal that EOF was reached.
Your are mistaken about the behaviour being different when $/ eq "\n". It doesn't matter what $/ is. If you only have one line, the second read will be undef.
$ echo "abc" | perl -E'$/ = undef; say defined(<>)||0 for 1..2;' 1 0 $ echo "abc" | perl -E'$/ = "\n"; say defined(<>)||0 for 1..2;' 1 0
You saw a difference in your tests because you passed two lines before EOF with $/ eq "\n", but only one line before EOF with !defined($/).
By the way, relying on the user to close STDIN between inputs creates a stinky interface.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: how to read STDIN interactively
by Allasso (Monk) on Feb 25, 2011 at 13:57 UTC | |
by ikegami (Patriarch) on Feb 25, 2011 at 19:14 UTC |