On Thu, Nov 8, 2012 at 7:42 AM, Marco van Kammen <mvankam...@mirabeau.nl> wrote:
> Yeah, so something like this:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $previous_month;
> my $previous_month_num;
>
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
>
> my @months = ( 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 
> 'OCT', 'NOV', 'DEC' );
>
> my $current_month = $months[$mon];
> my $current_month_num = $mon + 1;
>

Note that you could use the modulo operator to avoid the if...else

my $previous_month_num = (($mon-1) % 12) + 1;
my $previous_month = $months[$previous_month_num - 1];


> if ($current_month eq "JAN") {
>   $previous_month = "DEC";
>   $previous_month_num = "12";
> } else {
>   $previous_month = $months[$mon -1];
>   $previous_month_num = $mon;
> }
>
> print "current month = $current_month\n";
> print "current month number = $current_month_num\n";
> print "previous month = $previous_month\n";
> print "previous month number = $previous_month_num\n";
>
> seems to work... :-)
>
> Thanks all!
>
>
> Marco van Kammen
> Applicatiebeheerder
> ----------------------------
> Mirabeau | Managed Services    Dr. C.J.K. van Aalstweg 8F 301, 1625 NV Hoorn
> +31(0)20-5950550  -  www.mirabeau.nl
> Please consider the environment before printing this email

HTH, Ken

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to