in reply to Array_ref into Array_ref Help.

Just use unshift.

use Data::Dumper; my $array_ref = [ [ qw/a b c/ ], [ qw/d e f/ ], [ qw/g h i/ ], ]; print Dumper $array_ref; my $array_ref_b = [ [ qw/j k l/ ], [ qw/m n o/ ], [ qw/p q r/ ], ]; print Dumper $array_ref_b; unshift @$array_ref_b, @$array_ref; print Dumper $array_ref_b

Update: Suggested unshift because it looked like the OP wanted to prepend the contents of $array_ref to $array_ref_b: ## @{ $array_ref_b }= @{ $array_ref }.@{ $array_ref_b };

Replies are listed 'Best First'.
Re^2: Array_ref into Array_ref Help.
by Anonymous Monk on Apr 22, 2009 at 17:16 UTC
    Not really working loosing the value of $header.
      loosing [sic] the value of $header.

      I'm not really sure what you mean. If you still need the header, you should be unshifting it onto $array_ref_b, just like you were doing in your original code. That's assuming that what you really want in the end is something along the lines of [ $header, $array_ref, $array_ref_b ].

      unshift @$array_ref_b, @$array_ref; unshift @$array_ref_b, $header;
Re^2: Array_ref into Array_ref Help.
by Anonymous Monk on Apr 22, 2009 at 17:42 UTC
    This is almost how I would like to have it, but I need here is, lets say the end result would be like:
    a b c j k l d e f m n o g h i p q r

    Because from the data base the first element of the first array_ref is relative to first element of the second array_ref.
      Do you mean you want to assemble the arrays into multidimensional structures? You should probably read up on arrays of arrays in perllol. The short answer is you could do it using

      my @AoA = ($array_ref, $array_ref_b);

      What have you tried?

      my $ref_a = [ [ qw/a b c/ ], [ qw/d e f/ ], [ qw/g h i/ ], ]; my $ref_b = [ [ qw/j k l/ ], [ qw/m n o/ ], [ qw/p q r/ ], ]; for my $i (0..$#$ref_a) { push @{$ref_a->[$i]}, @{$ref_b->[$i]}; }
        That would work, one question to you would be:
        my $ref_a = [ [ qw/a b c/ ], [ qw/d e f/ ], [ qw/g h i/ ], [ qw/x y z/ ], [ qw/3 4 5/ ], [ qw/6 7 9/ ], ]; my $ref_b = [ [ qw/j k l/ ], [ qw/m n o/ ], [ qw/p q r/ ], ]; for my $i (0..$#$ref_a) { push @{$ref_a->[$i]}, @{$ref_b->[$i]}; }

        How could I assign maybe a empty value in order not get an error, if the results from one of the array_ref will be like the sample code here.