This will work under the assumption that all input files have the same number of lines. However, if you have for example

Sample of text-1.txt files:

Line_1:Line_1_1 Line_2:Line_2_2 Line_3:Line_3_3 Line_4:Line_4_4
Sample of text-2.txt files:
Line_5:Line_5_5 Line_6:Line_6_6
Sample of text-3.txt files:
Line_7:Line_7_7 Line_8:Line_8_8 Line_9:Line_9_9 Line_10:Line_10_10
the array would have the content 'Line_9_9' and 'Line_10_10' in the second column (where one would expect content from the second file only). This is because push simply appends at the end of the array.

To avoid that it would be better to use fixed indexing instead of push:

So

my $i = 0; while (<>) { # read from @ARGV chomp; push @{ $value[$i++] }, /:([^:]+)/; # get timestamp $i = 0 if eof; }
could be replaced by this
my $i = 0; my $filecount = 0; while (<>) { # read from @ARGV chomp; $value[$i++]->[$filecount] = /:([^:]+)/; # get timestamp if (eof) { $i = 0; ++$filecount; } }

This would put the timestamps always in the right places, but you would have to be prepared to have 'holes' in the array, if the input files have different number of lines.

You can test if an array cell has a value assigned with code like the following:

if (!exists $value[$line]->[$file]) { # no value assigned, there is a hole in the array } else { # value assigned }
Hope this helps! Update: forgot a closing brace in the new code block. It is now fixed.

In reply to Re^2: Concatenating arrays fetched from different text files by hexcoder
in thread Concatenating arrays fetched from different text files by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.