[EMAIL PROTECTED] wrote on 12/09/2005 02:31:03 
PM:
> Date: Fri, 09 Dec 2005 11:26:20 -0800
> From: "$Bill Luebkert" <[EMAIL PROTECTED]>
> Subject: Re: Perl code to get next date  Example : 12/31/2005 =>
>    01/01/2006
> To: sekhar kavuru <[EMAIL PROTECTED]>
> Cc: [email protected]
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=us-ascii
> 
> sekhar kavuru wrote:
> 
> > I need help with a generic function that can give the value of next 
day
> > Example : 12/31/2005 => 01/01/2006
> > 
> > I want to accomplish this without Cal::Date
> 
> use strict;
> use warnings;
> use Time::Local;
> 
> my @t = localtime;         # get epoch time for today
> $t[0] = 0; $t[1] = 0; $t[2] = 12;   # drop H:M:S back to noon
> $t[3]++;            # go forward a day
> 
> my $time = timelocal (@t);      # convert to epoch time
> 
> # Now you can use one of these for the rest:
> 
> @t = localtime $time;
> my $file = sprintf "%02u/%02u/%04u", $t[4]+1, $t[3], $t[5]+1900;
> print $file, "\n";
> 
> use POSIX;
> @t = localtime $time;
> $file = strftime "%m/%d/%Y", @t;
> print $file, "\n";

Bill-

my thought was similar but to do it in one line with all built ins and no 
modules. well two if you include printing it to screen, but the 
calculation is just one line.


###########start code###########

#! /usr/bin/perl
use strict;
use warnings;

my $next_day=localtime(time+(60*60*24));
print "tomorrow is $next_day\n";
__END__

#########end code###########


however that would probably confuse someone without explanation, yours 
leaves room for a nice explanation. so i think because of that it's 
better.


Sekhar-

mine uses the built-ins time() and localtime()

time() returns seconds since 1/1/1970 (epoch) and localtime() gives you a 
human readable date.

what i do is seed localtime with the current epoch, with 60 (seconds) 
times 60 (minutes) times 24 (hours) to advance it one full day.


thus every time you run it, it gives you tomorrow to the second it was 
run.

If you are looking for something that could be puzzling on upkeep if 
you're not an oddball like myself, yet completely portable, use my 
solution.
If you want something friendly to upkeep, use Bill's.

-Josh


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to