Parameter number 5 of localtime() is month number (0 for Janurary, 1 for Feburary ... 11 for December). So we need to convert the input string from a 3 character string (Jan, Feb, etc) to and integer from 0 to 11.
In a normal 3rd generation language (like C) we would have to use 12 if statements or a big case statement to assign the month number for each string (eg. if (strcmp(mmm, "Jun") == 0) mon=5;
). Perl has a nifty datatype called an associative array, this is like a normal array except the index value can be a string. I use these to lookup them month string and fetch then required number:
my %mon;
Here I've defined an associative array called mon.
@mon{qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/} = 0..11;
This creates array elements $mon{"Jan"}=0
, $mon{"Feb"}=1
thru $mon{"Dec"}=11
The above statement can be written a number of ways for example:
@mon{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
%mon = ("Jan", 0, "Feb", 1, "Mar", 2, "Apr", 3, "May", 4, "Jun", 5, "Jul", 6, "Aug", 7, "Sep", 8, "Oct", 9, "Nov", 10, "Dec", 11);
$mon{"Jan"} = 0;
$mon{"Feb"} = 1;
$mon{"Mar"} = 2;
$mon{"Apr"} = 3;
$mon{"May"} = 4;
$mon{"Jun"} = 5;
$mon{"Jul"} = 6;
$mon{"Aug"} = 7;
$mon{"Sep"} = 8;
$mon{"Oct"} = 9;
$mon{"Nov"} = 10;
$mon{"Dec"} = 11;