The sort is working fine, the error is in reading the data. You're overwriting the contents of @row
and pushing multiple references to it into @rows
. Instead, create a new @row
for each line of data:
my @rows;
while (<DATA>) {
chomp;
my @row = split "\t";
push (@rows, \@row);
}