in reply to Sort files descending by date

oog! Looking at that split I have no idea what you're trying to extract. Well, not at first glance. All you want is to extract the digit-and-underscore component before the file extensions. How about the simpler:

my @sorted_list = map {$_->[0]} sort { $b->[1] cmp $a->[1] } map { /([\d_]+)\.csv\.xml$/ ? [$_,$1] : [$_, 0] } @file_list;

Also, you should avoid using

next if ( $file =~ /^\./ );

One of these days it will come back to haunt you. It is wiser to use the more prosaic form:

next if $file eq '.' or $file eq '..'

Even if it doesn't look as cool because it lacks regexps.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: Sort files descending by date
by Scrat (Monk) on Jun 19, 2007 at 09:40 UTC

    Thanks for the reply Grinder.

    It worked like a charm - now prints out:
    WAN_DX_BNA_BNA_2007_06_30_00_22_32_641.csv.xml WAN_DX_BLV_BLV_2007_06_22_00_22_34_667.csv.xml WAN_DX_ACH_ACH_2007_06_13_00_10_37_051.csv.xml WAN_DX_BFN_BFP_2007_06_11_00_15_52_400.csv.xml WAN_DX_ALE_ALE_2007_06_10_00_10_39_106.csv.xml WAN_DX_ALD_ALD_2007_06_10_00_10_38_073.csv.xml WAN_DX_ACD_ACD_2007_06_10_00_10_38_042.csv.xml WAN_DX_ADY_ADY_2007_06_10_00_10_37_060.csv.xml