Beau E. Cox wrote:
> Hi -
>
> I give up. Can someone help? I want to 'dup' an
> IO::xxx handle to STDIN. My latest try is:
>
> #/usr/bin/perl
> use strict;
> use warnings;
> use IO::File;
> my $fh = new IO::File;
> $fh->open("< some.file") or die "cannot open some.file";
> open (STDIN, "<&$fh") or die "cannot dup \$fh: $!\n";
> print "\$fh duped\n";
> $fh->close;
>
> outputs:
> cannot dup $fh: Invalid argument
>
> A 'regular' file handle works:
>
> #/usr/bin/perl
> use strict;
> use warnings;
> open (IN, "< some.file") or die "cannot open some.file";
> open (STDIN, "<&IN") or die "cannot dup IN: $!\n";
> print "IN duped\n";
> close IN;
>
> outputs:
> IN duped
>
> What am I doing wrong?
>
> Aloha => Beau.
have you try:
#!/usr/bin/perl -w
use strict;
use Fatal qw(open);
use IO::File;
my $f = new IO::File;
$f->open('foo.txt');
open(STDIN,'<&' . $f->fileno);
print while(<STDIN>);
$f->close;
__END__
which prints the content of foo.txt
Make sure you dup STDIN back to what it should be after you finish reading
foo.txt
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]