On Wed, Aug 17, 2011 at 6:53 PM, Bryan R Harris
<[email protected]> wrote:
> How can I use the "safe" 3-argument open and still be able to read off a
> pipe?
What I have done in the past is manually compare the filename to '-'
and skip the opening and just assign STDIN to my file handle.
use strict;
use warnings;
my @filenames = qw(-);
@filenames = @ARGV if @ARGV;
for my $filename (@filenames)
{
my $fh;
if($filename eq '-')
{
$fh = \*STDIN;
}
else
{
open $fh, '<', $filename or die "Failed to open '$filename': $!";
}
# Etc...
}
__END__
Perhaps experienced Perl programmers know of better ways, in which
case I would be happy to learn them also. :)
--
Brandon McCaig <http://www.bamccaig.com/> <[email protected]>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <[email protected]>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/