in reply to Looping months and days

Please read this site's FAQ for info on how to post. Please check the info on formatting your post. Your post is hard to read.

I'm not sure exactly what you are asking for, but it sounds like you want code that do something based on the last 31 days each day. Even if I am on the wrong track, checking out these functions should help you:

  1. time
  2. localtime
  3. Time::Local's timelocal

Now for some (untested) code.

#Loop 31 times foreach (1..31) { # Set date to $_ days in the past. my $date = time() - $_*24*60*60 my ($day,$month,$year) = localtime($date)[3,4,5]; # cleanup raw localtime output $month++; $year = substr ($year, -2); # Print niceish (whitespace instead of 0) MM/DD/YY dates to string $date = sprintf "%2d/%2d/%2d", $month,$day,$year; #I'm reusing $da +te, I don't need its old value. # Fix whitespace. $date will now hold MM/DD/YY data. $date=~s/\s/0/g; print "MM/DD/YY:\t$date\n"; }

Here's a truncated bit of output:

MM/DD/YY: 06/17/01 MM/DD/YY: 06/16/01 MM/DD/YY: 06/15/01 MM/DD/YY: 06/14/01

I hope this helps.


TGI says moo