in reply to Opening multiple files
You could do something like this:
#!/usr/bin/perl -w use strict; my @fh; # open all files for my $i (0..$#ARGV) { open $fh[$i], "<", $ARGV[$i] or die $!; } while (1) { my @lines; # read one line from each file push @lines, scalar readline $fh[$_] for 0..$#ARGV; last unless defined $lines[0]; chomp @lines; print join(",", @lines), "\n"; }
$ ./950649.pl infile1 infile2 infile3 ... > outfile
(Note that you have to use readline with "complex" file handle expressions like $fh[$i], as <$fh[$i]> wouldn't work here.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Opening multiple files
by kielstirling (Scribe) on Jan 30, 2012 at 01:45 UTC | |
by Eliya (Vicar) on Jan 30, 2012 at 02:08 UTC | |
by kielstirling (Scribe) on Jan 30, 2012 at 02:11 UTC |