Over a million developers have joined DZone.

Sort File List By Month Name In Perl

·
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 best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}