Return to Snippet

Revision: 35738
at November 12, 2010 12:19 by numberwhun


Initial Code
#!/usr/bin/perl

use strict;
use warnings;

my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();

# You add 1 because the number in $month is based on a starting number of 0.  
# So, if $month is 0, then $monthnum is 1 (ie:  January)
# Adding 1 gets you a number from the list below.  

my $monthnum = $month + 1;

my %monthname = (
                  1 => 'January',
                  2 => 'February',
                  3 => 'March',
                  4 => 'April',
                  5 => 'May',
                  6 => 'June',
                  7 => 'July',
                  8 => 'August',
                  9 => 'September',
                 10 => 'October',
                 11 => 'November',
                 12 => 'December',
);

print("The present month is: $monthname{$monthnum}\n");

Initial URL

                                

Initial Description
This is a script that simply prints the current month.   I produced this a couple years ago and use it as a reference for using the localtime() function.

Initial Title
Print Current Month

Initial Tags
perl

Initial Language
Perl