in reply to Parsing/regex question

Unrelated to your problem ... here is a suggestion to simplify your code. Use POSIX to determine your dates:
print "=========== DATE INITIALIZATION ===========\n"; ############################################ # get dates in the mm/dd/yyyy format ############################################ use POSIX; print "Today is: " , strftime('%m/%d/%Y', localtime), "\n"; print "Tomorrow is: " , strftime('%m/%d/%Y', localtime(time + 86400)) +, "\n"; print "Yesterday is: " , strftime('%m/%d/%Y', localtime(time - 86400)) +, "\n";

Replies are listed 'Best First'.
Re^2: Parsing/regex question
by vxp (Pilgrim) on Jul 06, 2009 at 19:58 UTC

    incorporated into my code, less lines now :D

    thanks for the tip!

      Don't, it's wrong.

      86400 seconds sooner/later can be the same day.
      86400 seconds sooner/later can be two days earlier/later.

      use DateTime qw( ); my $today = DateTime->today( time_zone => 'local' ); my $tomorrow = $today->add ( days => 1 ); my $yesterday = $today->subtract( days => 1 ); print "Today is: ", $today ->strftime('%m/%d/%Y'), "\n"; print "Tomorrow is: ", $tomorrow ->strftime('%m/%d/%Y'), "\n"; print "Yesterday is: ", $yesterday->strftime('%m/%d/%Y'), "\n";

      Update: Added solution.
      Update: Fixed spelling of time_zone. (underscore was missing)

        In which case, we can use a CPAN module, such as Date::Simple:
        use Date::Simple ('date', 'today'); my $date = today(); print "Today is: " , $date, "\n"; print "Tomorrow is: " , $date + 1, "\n"; print "Yesterday is: " , $date - 1, "\n";

        Update: oops... didn't see your updated code

        cool! doing the following now:
        $today_tmp = DateTime->now(); $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); $today = $today_tmp->mdy('/'); $tomorrow = $tomorrow_tmp->mdy('/'); $yesterday = $yesterday_tmp->mdy('/'); print "Today: $today -=- "; print "Tomorrow: $tomorrow -=- "; print "Yesterday: $yesterday -=- ";

        Works perfectly!