Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Sort File List By Month Name In Perl

DZone's Guide to

Sort File List By Month Name In Perl

·
Free Resource
Sort a list of files by the month name


#!/usr/bin/perl -w
#
#
#
use strict;

my @mon = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my $mon;
@{$mon}{@mon} = (0..$#mon);

my $data = <
  
   {$line}->{mon} = $mon->{$ls[5]};

}

sub by_month ($$) {
    my ($a, $b) = (shift, shift);
    $list->{$a}->{mon} <=> $list->{$b}->{mon};
}

for my $line ( sort by_month keys %{$list} ) {
    print "$line\n";
}

  
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}