On 18/08/2011 01:35, John Delacour wrote:
At 17:53 -0500 17/08/2011, Bryan R Harris wrote:
How can I do a 3-argument open on STDIN? This doesn't work because the
3-argument open won't open STDIN when you tell it to open "-".
**************************************
@files = ("-");
for (@files) {
print reverse readfile($_);
}
[...]
That makes no sense to me at all. I see no mention of STDIN in the
script and see you are trying to open and read a single file named "-",
which is pretty odd.
Hi John
Bryan is referring to a poorly-documented feature of Perl, which as far
as I know is only described in perldoc perlopentut. This is what it says:
The Minus File
Again following the lead of the standard shell utilities, Perl's "open"
function treats a file whose name is a single minus, "-", in a special
way. If you open minus for reading, it really means to access the
standard input. If you open minus for writing, it really means to access
the standard output.
And the problem is that, while
open my $fh, '-';
or
open my $fh, '<-';
opens a copy of the STDIN filehandle, the three-argument form of open
open my $fh, '<', '-';
looks instead for a real file called '-' and fails if it doesn't find
one. Brandon's solution is the only one I can think of.
Rob
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/