I actually can't do it that way, this is a part of a custom perl module that someone wrote, and those are just 2 lines from the module.
On 03/16/04 00:06, James Taylor wrote:
I'm modifying a script someone wrote that basically reads a file file into STDIN, and I was curious if there was anyway of modifying the stdin value without having to first open the file, modify it, close the file, and then open it into stdin.
Ok, I think I see what you want: black magic
Try this:
#!/usr/bin/perl
package MySTDIN;
use strict; use warnings;
use Tie::Handle; our @ISA = qw(Tie::Handle);
sub TIEHANDLE { my $class = shift; open my $fh, '-'; bless $fh, $class; }
sub READLINE { my $self = shift; if (wantarray) { my @input; while (my $input = <$self>) { push @input, sprintf( "%3s %s", $., $input); } return @input; } else { my $input = <$self>; return undef unless defined $input; return sprintf( "%3s %s", $., $input); } }
package main;
use strict; use warnings;
tie *STDIN, 'MySTDIN'; print <STDIN>;
__END__
You just need to tie STDIN before it gets used, and alter the code in READLINE to alter the lines. Note you have to handle both scalar and array contexts.
I'm not completely sure of the correctness of the above. Use at your own risk.
Regards, Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>