Since your code doesn't produce a result and you haven't told us what you want, this is a guessing game.

On style, this: for my $i (0..$#$ref_a) is a super red flag. This sort of loop variable is a "non-Perl" way to do things and $# is deprecated anyway.

I guessed that you wanted to merge the $ref_b stuff into the $ref_a stuff and get a revised version of $ref_a reflecting a new sorted version of those updates (eg "j,k,l" should come before "x,y,z"),like this:

3 4 5 6 7 9 a b c d e f g h i j k l m n o p q r x y z

The code below shows how to do that..and what to do if you want numbers to appear after letters (sort order change)...

#!/usr/bin/perl -w use strict; use Data::Dumper; 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/ ], ]; #clone (deep copy) the lists in $ref_b into $ref_a #by appending them to the List of Lists (LoL) in $ref_a... foreach my $bref (@$ref_b) { push @$ref_a,[@$bref]; } #now add 99 to each list in $ref_b (a new "column") #so that we can see that modifying b no longer #modifies a, meaning that the "deep copy" worked! @$ref_b = map{[@$_,99]}@$ref_b; print Dumper($ref_a,$ref_b); # here is a way to sort the LoL by "column" # without using [$i] indicies... @$ref_a = sort by_column @$ref_a; sub by_column { my @a_cols = @$a; my @b_cols = @$b; foreach my $item_a (@a_cols) { my $item_b = shift (@b_cols); my $compare_not_equal = $item_a cmp $item_b; return $compare_not_equal if $compare_not_equal; } return 0; } print "Sorted results in \$ref_a, reference to LOL\n"; foreach (@$ref_a) { print "@$_\n"; } # if we want the numbers to be greater than the alpha # characters, then we replace # my $compare_not_equal = $item_a cmp $item_b; # with something like: # my $compare_not_equal = myCompare($item_a,$item_b) # where myCompare returns the standard >0,<0,=0 for # what the order you want __END__ OUTPUT: $VAR1 = [ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ], [ 'g', 'h', 'i' ], [ 'x', 'y', 'z' ], [ '3', '4', '5' ], [ '6', '7', '9' ], [ 'j', 'k', 'l' ], [ 'm', 'n', 'o' ], [ 'p', 'q', 'r' ] ]; $VAR2 = [ [ 'j', 'k', 'l', 99 ], [ 'm', 'n', 'o', 99 ], [ 'p', 'q', 'r', 99 ] ]; Sorted results in $ref_a, reference to LOL 3 4 5 6 7 9 a b c d e f g h i j k l m n o p q r x y z

In reply to Re: Undefined Array Reference by Marshall
in thread Undefined Array Reference by Anonymous Monk

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.