in reply to Re^2: Sorting array
in thread Sorting array

I really can't tell what the problem is

This regex /EK(\d+)\D/ captures only the numerics after the EK which is 101 for all the records. Expand the regex to capture the full key (less the last suffix letter if present).

#!/usr/bin/perl -w use strict; use warnings; my @ar1 = qw( F40_I_VBBG_RI50-FMVSS301n-2SR424M-HCH-D_01EK101.a3db F40_I_VBBG_RI50-FMVSS301n-2SR424M-HCH-D_01EK101a.a3db F40_I_VBBG_LR50-ECR17p-2SR424M-HCH-D_01EK101g.a3db F40_I_VBBG_LR50-ECR17p-2SR424M-HCH-D_01EK101k.a3db F40_I_VBBG_LR50-ECR17p-2SR424M-HCH-D_01EK101.a3db ); my %latest; for (sort @ar1){ if (/(.*?)[a-z]?\.a3db/){ $latest{$1} = $_; } else { warn "No match for $_"; } } print "$_\n" for reverse sort values %latest;
poj