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
Premature optimization is the root of all job security

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
    Thanks a lot Grandfather, the trick of printing was what I needed. As for you 2teez, I really don't understand your attitude. I explicitly said where I am stuck, so I needed help with that. You didn't want to help, fair enough, but please don't judge people you don't know.

      Where is the judgement? I don't see it. I simply refer you to a link that boldly stated among other things that ..Be precise about the correct behavior / desired output. Additional background about what you are trying to do and what you have tried also helps.

      If I don't want to help, I would not even put in a word to start with.
      I don't think "I want to .." like your OP says shows what you have tired and I don't think asking to shows some what of what you have tired a crime.
      We all came here either to help or to be helped, and then make the world a better place!

      Till you come out of the shadows, enjoy yourself friend!

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me