|Just another Perl shrine|
Re^5: $_ not set in while <>by kcott (Bishop)
|on Jun 06, 2021 at 06:28 UTC||Need Help??|
I think the issue here is that the OP wrote "read a file", not "read from the keyboard". If the sentinel value is detected, then processing of the file should stop; however, I think it's reasonable to assume that if no sentinel value is detected, then processing of the file should stop at the end of the file.
Note that in the examples below, I used a common alias of mine:
Here's a file that simulates your keyboard input. I've added an extra line that is to be ignored:
That is processed (almost) identically to your keyboard input:
I said "almost" because, as you may have noticed, there's a dangling "list of letters: " prompt as the last line of output.
However, if there's no sentinel value, processing does not stop at the end of the file; instead, the code is stuck in a loop. Also, warnings are emitted. Both of those things are what ++ikegami predicted.
Consider this slightly different input file (without a sentinel):
Here's what happens:
The screen output stopped there; I used Ctrl-C to get back to my shell prompt. Of course, I could've typed one of the sentinel values (quit|exit|q) but would you expect users to know what those values were; and even if they did, would you expect them to do this in the "production" environment you described.
Update: I started to compose my response before your post had any updates. After posting, I see you've added three updates. That's not a complaint about the updates; just advice on what I was responding to.