in reply to Referencing an array

while (not eof DATA) { # Read four lines and store them in the @record array my @record = ( scalar(<DATA>), scalar(<DATA>), scalar(<DATA>) ); $c = $c + 3; # Remove the new-line from the end of the lines chomp @record; # Store a reference to this @record instance # in the @data array. $data[$record[0]] = [$record[1],$record[2]]; } # Arrays start at zero and the sort below will barf if you # don't have each element in the array be an array ref $data[0] = [] unless $data[0]; close DATA; my @sorted = sort { $a->[0] <=> $b->[0] } @data; print Dumper(@sorted)."\n"; for ($i = 0; $i < ($c); $i++) { next unless defined($sorted[$i]); for ($j = 0; $j <= 1; $j++) { print $sorted[$i][$j]."\n" if defined $sorted[$i][$j]; } }
You will need to figure out what to do about $data[0]. I wasn't sure if the 1,2,3... from your data were important as values or they just defined order. If you the values are just to maintain order, then you could  shift @data instead of creating the dummy  $data[0] = ....

Plenty left for you to think through and tinker with.