Hi Peter.
This is not actually a bug. Nor is it specific to IO::Prompter.
In fact, this is standard Perl behaviour for readline().
For example:
perl -E '@ARGV = "some_file"; while(<>){ print }'
will print some_file as expected. But
perl -E '$x = <>; @ARGV = "some_file"; while(<>){ print }'
will read into $x and then read from STDIN instead of some_file.
In Perl, the very first readline from *ARGV magically sets *ARGV to read
from whatever
filename is in @ARGV at the time of that first readline. Changing the
contents
of @ARGV subsequent to that first read does not affect *ARGV in any way,
unless *ARGV has been closed in the meantime.
As the above examples show, this behaviour is the same whether that very
first
readline is inside a call to prompt(), or is explicit (as above).
The workaround is either to close *ARGV before slurping the file:
perl -E '$x = <>; close *ARGV; @ARGV =
"some_file"; while(<>){ print }'
perl -MIO::Prompter -E '$x = prompt "foo"; close *ARGV; @ARGV =
"some_file"; while(<>){ print }'
or (for IO::Prompter only) to use the special -stdio option on that first
input:
perl -MIO::Prompter -E '$x = prompt "foo", -stdio; @ARGV = "some_file";
while(<>){ print }'
...which causes prompt() to read directly from *STDIN, rather than doing a
"magic open" on *ARGV.
Hope this helps,
Damian