Skip Menu |

This queue is for tickets about the IO-Prompter CPAN distribution.

Report information
The Basics
Id: 104232
Status: resolved
Priority: 0/
Queue: IO-Prompter

People
Owner: Nobody in particular
Requestors: Peter [...] PSDT.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Stops diamond operator working
Date: Tue, 05 May 2015 06:33:56 -0700
To: bug-IO-Prompter [...] rt.cpan.org
From: Peter Scott <peter [...] psdt.com>
perl -MIO::Prompter -E '@ARGV = "some_file"; while(<>){ print }' will print some_file as expected. But perl -MIO::Prompter -E '$x = prompt "foo"; @ARGV = "some_file"; while(<>){ print }' will prompt for foo and then read from STDIN instead of some_file. Regards, Peter
Subject: Re: [rt.cpan.org #104232] Stops diamond operator working
Date: Wed, 6 May 2015 06:57:50 +1000
To: bug-IO-Prompter [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
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