in reply to create array of arrays from multiple files
Array of arrays is probably the best data structure. The trick in using it is to pull elements off the front of each nested array to get the output data as you need it:
#use strict; use warnings; my $File1 = <<FILE; 13 34 32 20 43 FILE my $File2 = <<FILE; 22 15 27 33 48 65 34 FILE my $File3 = <<FILE; 18 20 22 45 44 32 12 26 FILE my @data; for my $file (\$File1, \$File2, \$File3) { open my $fIn, '<', $file or die "Can't open $file: $!\n"; push @data, []; while (<$fIn>) { chomp; push @{$data[-1]}, $_; } } while (grep {@$_} @data) { printf "%s\n", join "\t", map {$_ // ''} map {shift @$_} @data; }
Prints:
13 22 18 34 15 20 32 27 22 20 33 45 43 48 44 65 32 34 12 26
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: create array of arrays from multiple files
by Anonymous Monk on Jan 28, 2016 at 20:28 UTC | |
by 2teez (Vicar) on Jan 28, 2016 at 20:57 UTC |