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;

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
-----Original Message-----
From: David Precious [mailto:dav...@preshweb.co.uk]
Sent: Thursday, November 08, 2012 12:57 PM
To: beginners@perl.org
Subject: Re: Date::Manip question

On Thu, 8 Nov 2012 12:53:31 +0100
Rob Coops <rco...@gmail.com> wrote:
> Something like the below would do perfectly fine...
>
> 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_mont_num = $mon;
> my $previous_month = $months[$mon -1];
> my $previous_month_num = $mon -1;

You'll have an interesting previous month in January :)



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



--
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