pengyou_ah has asked for the wisdom of the Perl Monks concerning the following question:
where myscript.pl looks something like this:ls *.txt | myscript.pl
I've seen other code snippets using a pipe in the open(), but I'd rather do it as shown if possible. Any help appreciated. If I must use a pipe in open(), how can I iterate through the results of ls *.txt?#!/usr/bin/perl -w my $filename = ""; my $inputline = ""; my $siteid = ""; my $sitename = ""; foreach $filename (@ARGV){ open(FILE,$filename) or die "can't open file: $!\n"; print "processing $filename\n"; while ($inputline = <FILE>){ if ($inputline =~ m/^Station/){ print "$inputline\n"; } } close FILE; }
update (broquaint): added <code> tags and dropped extraneous <br> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: command line pipe
by blokhead (Monsignor) on Jul 23, 2003 at 04:01 UTC | |
by pengyou_ah (Initiate) on Jul 23, 2003 at 06:25 UTC |