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.
I think what you want is a traditional filter:
=== myfilter.pl === #!/usr/bin/perl
use strict; use warnings;
while (my $line = <>) { chomp($line); $line =~ s/^/sprintf("%3s ", $.)/e; print "$line\n"; }
__END__
piping it to its own STDIN produces
cat myfilter.pl | perl myfilter.pl
1 #!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 6 while (my $line = <>) { 7 chomp($line); 8 $line =~ s/^/sprintf("%3s ", $.)/e; 9 print "$line\n"; 10 }
See perldoc perlopentut, section "Filters"
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>