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 Mar 15, 2004, at 11:01 PM, Randy W. Sims wrote:

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.

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>




Reply via email to