in reply to Re: Sort files by date in the file name.
in thread Sort files by date in the file name.

A number that must be used as a key ..... The first and last column should be the sort keys.
  • Comment on Re^2: Sort files by date in the file name.

Replies are listed 'Best First'.
Re^3: Sort files by date in the file name.
by Anonymous Monk on Jul 07, 2016 at 23:50 UTC

    A number that must be used as a key ..... The first and last column should be the sort keys.

    :) you gave sample input and sample output

    the sample output does not appear in the sample input

    its not clear what you mean by "first column code" and I cannot deduce/guess from the sample you provided

    The word explanations do not clarify which part is which

      See this example: 1020300000_XXXXXXXXX_20160707193000.TXT 1020300000_XXXXXXXXX_20160707170000.TXT I need to return only the oldest file using the file name date. 1020300000_XXXXXXXXX_20160707170000.TXT
        #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my @in = qw/ 1020300000_XXXXXXXXX_20160707193000.TXT 1020300000_XXXXXXXXX_20160707170000.TXT 1020300000_XXXXXXXXX_20160707190000.TXT /; my $final = GiveMeItTheThingIWant( \@in ); dd( $final, \@in ); sub GiveMeItTheThingIWant { my( $in ) = @_; my @ordered = map { $$_[1] } sort { $$a[0] cmp $$b[0] } map { #~ my( $left, $right ) = $_ =~ m{^([^_]+)_[^_]+_([^_]+)}; my( $left, $middle, $right , $txt ) = split /[_\.]/, $_; [ $right, $_ ]; } @{$in}; return $ordered[0]; #~ return '1020300000_XXXXXXXXX_20160707170000.TXT'; } __END__

        Ok thats easier to deduce from, its easier to understand the question if you take one file name, break it into parts, and label the parts so they match the word descriptions ... I'll be back in 1min