date --date : the perl way

Discussion in 'Perl' started by Me, Dec 9, 2005.

  1. Me

    Me Guest

    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?
    Me, Dec 9, 2005
    #1
    1. Advertising

  2. Me <> wrote in news::

    > 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
    `$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
    $!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
    $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
    ;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
    Eric J. Roode, Dec 9, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    599
    Matthew Speed
    Nov 8, 2003
  2. Brian Candy
    Replies:
    2
    Views:
    1,159
    Janaka
    Feb 18, 2004
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,251
    Michael Borgwardt
    May 30, 2004
  4. Matt
    Replies:
    2
    Views:
    515
    Pete Becker
    Nov 8, 2003
  5. Matt
    Replies:
    3
    Views:
    719
    Richard Heathfield
    Nov 8, 2003
Loading...

Share This Page