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($_);
}
sub readfile {
open(my $fh,"<",$_[0]) or die "$me: Couldn't open $_[0]: $!\n";
my(@fc) = <$fh>;
close($fh) or die "$me: Couldn't close $_[0]: $!\n";
if ($fc[0] =~ /\r/) { @fc = map { s/\r\n?/\n/g; split /(?<=\n)/ } @fc; }
if (wantarray()) { return @fc; }
else { return join('', @fc) }
}
**************************************
How can I use the "safe" 3-argument open and still be able to read off a
pipe?
- Bryan
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/