in reply to Populate and sort AoA

In your for (0..$#display) loop, you check $display[$#display][0] to see if it matches something. The problem is, you may have already spliced an element of the array away, and so the array is now smaller.

For example, you may have an array of 4 elements ($#display == 3). Then you find an element again, so you splice it out, so the array is now 3 elements. However, your loop still is "0..$#display" which was "0..3" at the time that perl evaluated it. So you get back to evaluating $display[3][0] - and perl needs to autovivify $display[3] in order to evaluate $display[3][0]. That is the problem.

Solution 1 is to add a "last" right after the splice. Once you've found the serial number, you're not going to find another one - the purpose of this loop is to keep things unique. So there can't be another one - just get out, and you won't evaluate past the end of the array anymore.

Solution 2 is to move to HoH's. In this world, I would have a structure like this:

%data = ( serial_number => { A => 0 or 1, B => 0 or 1, # etc. order_stamp => number }, # etc. );
Then, I'd have an order number outside the loop, and each time I touch a serial number, I'd also assign $data{$serial}{order_stamp} = ++$order. Then, to get the desired order, just do a reverse sort on the order_stamp:
@serial_order = reverse sort { $data{$a}{order_stamp} <=> $data{$b}{ +order_stamp} } keys %data;
But if you're using AoA's for space reasons, well, you'll have to live with scanning for your desired serial number (sounds slow to me ;->). Note that rather than having A, B, C, D as separate keys, you can just put them in a 'data => []' key to get them all quickly. Up to you.