in reply to Date Manipulation

Of course there is a way to do this. Computers are pretty smart nowadays. :)

You might try a Google Codesearch for routines called yesterday, or even just a normal googling of search.cpan.org for yesterday

Since this sounds a lot like a homework problem, you probaby won't be able to get away with using Date::Simple:

use Date::Simple qw(today); $date = today() - 1; print $date;

or Date::Manip:

use Date::Manip; $date = ParseDate("yesterday"); print $date;

or Date::PeriodParser:

use Date::PeriodParser; $date = parse_period("yesterday"); print scalar localtime( $date );

or many other modules which can handle this sort of thing. You can always look at their source to see how they did it.

Good luck :)

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re^2: Date Manipulation
by Corion (Patriarch) on Dec 17, 2006 at 21:07 UTC

    If you disregard timezones, my favourite method of calculating yesterday's date is the following:

    my $yesterday = localtime; sleep( 86400 ); print "Yesterdays date is $yesterday\n";

    People might complain that the runtime is a bit too long, but I'm sure one can reduce the runtime by rewriting this program in C, Haskell or Perl6.

      Yep. Exactly, 'sleep' subroutine should be rewritten for better performance...