in reply to Reading arrays
As you can see, this will bomb if the first file contains more lines than the other two files - recursive turnary operator, anyone? There is lots of improving that can be done to this rather unelegant piece of code . . . but this does the trick - hope this helps.use strict; my (@lines1, @lines2, @lines3); &load_array(\@lines1, "foo1.dat"); &load_array(\@lines2, "foo2.dat"); &load_array(\@lines3, "foo3.dat"); for (my $i = 0; $i < @lines1; $i++) { my ($word2) = split(/ /, $lines2[$i]); my ($word3) = split(/ /, $lines3[$i]); print "$lines1[$i]:$word2:$word3\n"; } sub load_array($$) { my ($a_ref, $file) = @_; open (FILE, $file) or die "Can't open $file:$!\n"; @{$a_ref} = <FILE>; close FILE; chomp @{$a_ref}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Reading arrays
by Anonymous Monk on Jul 31, 2000 at 22:34 UTC | |
by jeffa (Bishop) on Aug 01, 2000 at 02:15 UTC |