in reply to Improve my Code: Date List

All those dates screams for a search on CPAN, unless you want to re-invent wheels.

Replies are listed 'Best First'.
Re^2: Improve my Code: Date List
by cheech (Beadle) on Jun 17, 2009 at 23:58 UTC
    I do want to reinvent wheels until I understand the wheel well enough to trust someone else's.
      why dont use already existing date modules Eg:- Date::Calc For instance the code can be simplified to
      use strict;
      use warnings;
      use Date::Calc qw(Today Add_Delta_Days);
      
      my $today = sprintf("%02d%02d%02d",Today());
      
      my $year = 1986;
      my $month = 1;
      my $day = 1;
      my $offset =0 ;
      my $print_date = 0;
      
      while ($today > $print_date){
              my ($new_year,$new_month,$new_day)= Add_Delta_Days($year,$month,$day, $offset);
              $print_date =  sprintf("%02d%02d%02d",$new_year,$new_month,$new_day);
              print "$print_date\n";
              $offset++;
      }
      
      
      Depending on your req you can alter where ever needed
      Cheers