date --date : the perl way

M

Me

I need to get the past 5(x) months for certaing calculations. What I
have is listed below:

########################################
my $year, $month_str, $month_int;


foreach my $count (1..5) {
$year = `date --date '$count months ago' +"%Y"`;
chop($year);
$month_str =`date --date '$count months ago' +"%b"`;
chop($month_str);
$month_int =`date --date '$count months ago' +"%m"`;
chop($month_int);
print "\n $year:$month_str:$month_int";

}
########################################

This works as expected, the problem is I am using a shell command and I
would like to move away from it. Is the perl module that is able to take
parameters juat like the 'date' command?
 
E

Eric J. Roode

Me said:
This works as expected, the problem is I am using a shell command and I
would like to move away from it. Is the perl module that is able to take
parameters juat like the 'date' command?

There are many date-processing modules. None (that I know of) take
parameters that match those of the `date` command, but most of them provide
ways of specifying what you're looking for.

Have you looked at CPAN?

P.S.: comp.lang.perl is a defunct newsgroup. General perl questions are to
be posted to comp.lang.perl.misc, and questions about modules are to be
posted to comp.lang.perl.modules. For your future postings.

--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top