[sf-perl] Perl's to_date() equivalent
David Fetter
david at fetter.org
Fri Sep 1 14:59:00 PDT 2006
On Fri, Sep 01, 2006 at 02:42:00PM -0700, Loo, Peter # PHX wrote:
>
> Hellow there.
>
> Per Andy's recommendation, I went ahead and had DataTime.pm
> installed on our test node. It turned out that the date calculation
> is taking approximately 11 seconds for every 5,000 records. Is
> there something a bit faster? Here is my code:
Are you sure you can't do this with the DBMS's facilities? It seems
to me that Perl's are what you use when you don't have a DBMS date
library available. Also, could you explain in english what the code
is supposed to be doing?
Cheers,
D
> $counter = 0;
> while ( @cur = $sth->fetchrow() ) {
> if ($counter >= 5000) {
> printf(STDERR "$counter - %s", `date`);
> $counter = 0;
> }
> if ($prev[0] == $cur[0] && $prev[1] == $cur[1]) {
> ($pyear, $pmon, $pday) = split('-', $prev[7]);
> ($cyear, $cmon, $cday) = split('-', $cur[2]);
> $prev_cted = DateTime->new( year => $pyear, month => $pmon, day =>
> $pday );
> $cur_rxdte = DateTime->new( year => $cyear, month => $cmon, day =>
> $cday );
> ###########################################################
> # COMMENTS: Minus current rx_fill_dte with previous cted. #
> ###########################################################
> $dur = $prev_cted->subtract_datetime_absolute($cur_rxdte);
> $p_minus_c = $dur->in_units( 'days' );
> if ($p_minus_c >= 0 || ($p_minus_c < 0 && $p_minus_c <= $cur[5]))
> {
> $prev_cted->add( days => $cur[4] );
> $cur[7] = $prev_cted->ymd;
> $cur[6] = "C";
> }
> elsif ($p_minus_c < 0 && $p_minus_c > $cur[5]) {
> $cur_rxdte->add( days => $cur[4] );
> $cur[7] = $cur_rxdte->ymd;
> $cur[6] = "R";
> }
> }
> @prev = @cur;
> $rec = join($delimiter, @cur);
> print PIPE "$rec\n";
> $counter++;
> }
>
> $sth->finish;
> $dbh->disconnect();
> close(PIPE);
>
>
> Peter
>
> -----Original Message-----
> From: sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.org
> [mailto:sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.or
> g] On Behalf Of David Fetter
> Sent: Friday, August 25, 2006 10:04 AM
> To: San Francisco Perl Mongers User Group
> Subject: Re: [sf-perl] Perl's to_date() equivalent
>
> On Fri, Aug 25, 2006 at 11:58:52AM -0500, Andy Lester wrote:
> >
> > On Aug 25, 2006, at 11:56 AM, David Fetter wrote:
> >
> > > Try Date::Manip from CPAN :) It's not the fastest date munging
> > > library there, but it's very flexible.
> >
> > I'd recommend DateTime as the standard at this point.
>
> Thanks for the update. :)
>
> My information was pretty old.
>
> Cheers,
> D
> --
> David Fetter <david at fetter.org> http://fetter.org/
> phone: +1 415 235 3778 AIM: dfetter666
> Skype: davidfetter
>
> Remember to vote!
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
>
> This E-mail message is for the sole use of the intended recipient(s) and
> may contain confidential and privileged information. Any unauthorized
> review, use, disclosure or distribution is prohibited. If you are not
> the intended recipient, please contact the sender by reply E-mail, and
> destroy all copies of the original message.
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
--
David Fetter <david at fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter
Remember to vote!
More information about the SanFrancisco-pm
mailing list