Over a million developers have joined DZone.

Sort By Month Name In Perl

DZone's Guide to

Sort By Month Name In Perl

· ·
Free Resource
Sort by 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 = ('Aug', 'Nov', 'Jun');

sub by_month {
    $mon->{$a} <=> $mon->{$b};

print join $/, (sort by_month @data);
print $/;

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}