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:
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