I just read FAQ on finding out yesterday's time.

I see that one of the easy way to find out is

my $date = scalar localtime( ( time() - ( 24 * 60 * 60 ) ) );
print "$date\n";

and it works fine for me

I also see lot of modules that will make life easier for beginners.. but since I was learning reference, I wanted to try this on my own
since Leap year is not a huge factor, so

my @Jan = (1..31);
my @Feb = (1..29);
my @Mar = (1..31);
my @Apr = (1..30);
my @May = (1..31);
my @Jun = (1..30);
my @Jul = (1..31);
my @Aug = (1..31);
my @Sep = (1..30);
my @Oct = (1..31);
my @Nov = (1..30);
my @Dec = (1..31);

my @cal_r = [ @Jan,@Feb,@Mar,@Apr,@May,@Jun,@Jul,@Aug,@Sep,@Oct,@Nov,@Dec ];

for my $i ( 0 .. $#cal_r ) {
   for my $j ( 0 .. $#{ $cal_r[ $i ] } ) {
          print "$cal_r[ $i ][ $j ]\n";
   }
}

and then just check to see if it's first day of the month and if it is, go through @cal_r and find the previous month and find the last array item.. Algorithm seems to be correct but I cannot get to the item the way I thought I could.

What would be the correct syntax if I knew the date? say Apr 1st to find the yesterday's date given above?

I was thinking something along the line of

for my $i ( 0 .. $#cal_r ) {
   if ($cal_r[$i][0]) {
         print "yesterday is $cal_r[$i-1][lastday]\n"
   }
}



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to