DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Sort By Month Name In Perl

  • submit to reddit
        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 $/;