gotta add the caveat about
$a and
$b -- i know this is example code, but don't use those variable names .. they are special global variables for
sort
Can't tell if you really need hardcoded values or if you just flattened it for an example, but if the former you can just do (this should also help visualize the data structure):
use strict;
use warnings;
my @matrix = (
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ],
);
use Data::Dumper;
print Dumper \@matrix;
print $matrix[1]->[2] . "\n"; # prints "6"