in reply to How to concatenate a generic array of arrays and an array of hashes

Borrowing hexcoder's suggestion here, the following code will get want you want (if I understand the problem correctly).
#!/usr/bin/perl use strict; use warnings; my @value; my $col_count = 0; while (<>) { # read from @ARGV (sample.txt sample_2.txt sample_3.txt) chomp; my (undef, @data) = split /:/; my $row_count = 0; for my $info (@data) { $value[$row_count++][$col_count] = $info; } ++$col_count; } for my $v (@value) { print join(" ", @$v), "\n"; }
Using your 3 sample files, this prints:
Line_1_1 Line_2_1 Line_3_1 Line_4_1 Line_5_1 Line_6_1 Line_7_1 Line_1_2 Line_2_2 Line_3_2 Line_4_2 Line_5_2 Line_6_2 Line_7_2 Line_1_3 Line_2_3 Line_3_3 Line_4_3 Line_6_3 Line_6_3 Line_7_3 Line_1_4 Line_2_4 Line_3_4 Line_4_4 Line_5_4 Line_6_4 Line_7_4
Chris

Replies are listed 'Best First'.
Re^2: How to concatenate a generic array of arrays and an array of hashes
by thanos1983 (Parson) on Jul 06, 2014 at 18:54 UTC

    Hello Christoforo,

    Thanks for your time and effort to reply to my question. Well unfortunately this is not exactly what I want to do. My current solution is exactly what I want.

    Sample of output using 2 dimension arrays:

    $VAR1 = [ [ 'Line_1_3', 'Line_2_3' ], [ 'Line_3_3' ], [ 'Line_4_3', 'Line_5_3', 'Line_6_3', 'Line_7_3' ] ];

    Sample of array with hashes:

    $VAR1 = { 'sample.txt' => [ 'Line_1_3', 'Line_2_3' ], 'sample_2.txt' => [ 'Line_3_3' ], 'sample_3.txt' => [ 'Line_4_3', 'Line_5_3', 'Line_6_3', 'Line_7_3' ] };

    The reason is that possibly the files are not the same in line (size) etc. etc. I am trying to retrieve the arrays one by one so I can play around with it.

    I have found a way to print all data and also to print individual 1 by one the elements but not the arrays. I have an idea in my mind on how to solve it. I did not had the time to work on it, that is the reason that I have not updated my solution.

    But thanks again for your time and effort and sorry if my sketch is not so clear.

    Seeking for Perl wisdom...on the process...not there...yet!
      Each file contains data, I import the data on arrays then I short them on array of arrays
      I don't know what exactly you wish to do - do you mean sort?

      If you want to sort them, how would your output appear?

      You stated your solution is what you want.

      I have found a way to print all data and also to print individual 1 by one the elements but not the arrays.
      I don't know what you mean in the statement above. How do you want to print the arrays?

        Hello Cristoforo,

        I am trying to read n number of *.txt files as argument inputs. Each file contains infinite n number of lines in the file. I want to extract the the 4th element of each line. Each element of each line is separated with a column ":".

        Line example:

        Line_1:Line_1_1:Line_1_2:Line_1_3:Line_1_4

        After collecting each element from each line I want to put them on an array so I am able to manipulate the values of each element.

        The reason that I am using array of arrays is that I do not know the number of *.txt files that I am going to use.

        As a second step I am trying to print the collected values based on order of the files separated with a space in between.

        Sample of the expected output:

        Line_1_3 Line_3_3 Line_4_3 Line_2_3 Line_5_3 Line_6_3 Line_7_3

        Each column represents the *.txt file that was loaded. For example if we had loaded the sample.txt it would be column 1, sample_2.txt would be column 2 and sample_3.txt would be column 3.

        I hope this explains more and produces less confusion.

        Thanks for your time and effort to assist me.

        Seeking for Perl wisdom...on the process...not there...yet!