On Thu, Nov 8, 2012 at 12:53 PM, Rob Coops <rco...@gmail.com> wrote:

>
> On Thu, Nov 8, 2012 at 11:56 AM, Marco van Kammen 
> <mvankam...@mirabeau.nl>wrote:
>
>>  Hi List,****
>>
>> ** **
>>
>> For a logrotation and cleanup script I want to fill the following
>> variables.****
>>
>> ** **
>>
>> my $current_month =                    (should be Nov)****
>>
>> my $current_mont_num =           (should be 11)****
>>
>> my $previous_month =                 (should be Oct)****
>>
>> my $previous_month_num =     (should be 10)****
>>
>> ** **
>>
>> I’ve been looking at the module Date::Manip to get this going, but I
>> can’t seem to get it working.****
>>
>> ** **
>>
>> Any help in the right direction would be appreciated.****
>>
>> ** **
>>
>> With Kind Regards,****
>>
>> ** **
>>
>> ** **
>>        *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   [image: Mirabeau]        Please
>> consider the environment before printing this email
>>
>>
> Hi Marco,
>
> For this I would nto bother with Date::Manip but just use time.
>
> 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;
>
> print
> "$current_month\n$current_mont_num\n$previous_month\n$previous_month_num\n";
>
> Easy enough and without a module needed a lot more portable without a lot
> of work.
>
> Regards,
>
> Rob Coops
>

Yeah a minor update... $mon starts counting at 0 so for the current month
number add 1 and for the previous month number do not substract 1. :-)

my $current_month = $months[$mon];
my $current_mont_num = $mon + 1;
my $previous_month = $months[$mon -1];
my $previous_month_num = $mon;

<<blank20ad.gif>>

<<blank1c63.gif>>

<<miralogo69b6.png>>

<<blank52fd.gif>>

<<leaf1fbe.gif>>

<<blank4113.gif>>

Reply via email to