in reply to Reading a file

It really depends on what you mean by passing each line to another program: 1)Do you mean, call another program with each line as the arguments? or 2) Do you mean, pipe each line to another program's standard input? (or do you mean something altogether different?)

# 1 #!/usr/bin/perl -w use strict; my $other_program = 'echo'; while(<>){ chomp; system($other_program, $_); } __END__ # 2 #!/usr/bin/perl -w use strict; my $other_program = 'tr [a-z] [A-Z]'; open(OTHER, "|$other_program") || die "Kant: $!"; while(<>){ print OTHER $_; } close OTHER; __END__

Replies are listed 'Best First'.
Re: Re: Reading a file
by ep (Initiate) on Mar 08, 2001 at 01:34 UTC
    Thanks for everyone's help...I'm where I need to be. There were some questions about what I'm wanting to with the data from the file. I would like to take each record of the file (one at a time) and pass that record as an argument to another perl script, shell script, etc. that performs data extraction based on the argument being passed in (i.e. zip code). Hope this clears up any of the confusion! Thanks- ep