[Buffalo-pm] Question: How to iterate through 2 arraysandmerge columns
John Macdonald
john at perlwolf.com
Tue Jul 5 08:03:00 PDT 2005
On Tue, Jul 05, 2005 at 10:34:47AM -0400, Kevin Eye wrote:
> I don't understand why your suggestion wouldn't work, Dan. I don't see
> anything wrong with the pipes.
aside from the pointless use of cat...
Any time that you have a command pipeline:
cat file | foo [args]
you can run just the single command instead:
foo < file [args]
For many commands, like the instance of awk that is being
discussed, you can give a file (list) as part of the arguments
so you (often) don't need the '<' in front of the filename.
So:
my @red_elements = `/bin/cat file1 | awk \'{print "$4 $5 $6 $7"}\'`;
my @green_elements = `/bin/cat file2 | awk \'{print "$4 $5 $6 $7"}\'`;
can be written:
my @red_elements = `awk \'{print "$4 $5 $6 $7"}\' file1`;
my @green_elements = `awk \'{print "$4 $5 $6 $7"}\' file2`;
I was just about to write the same sort of code as Kevin to
do the whole job in Perl, reading the files a line at a time
instead of slurping everything at once. (Slurping is useful
until you use it with an input file that is too big - then
you start swapping and slow down to a crawl with a program
that "always ran fine before". When this happens months or
years after you wrote the original script, it takes a while
to figure out what's going on - you'll often spend a lot of
time looking for problems outside the script before realizing
that this has been a potential problem that has been lurking
all along and not some new circumstance.)
--
--
More information about the Buffalo-pm
mailing list