none

Tkil tkil-sdpm at scrye.com
Wed Apr 23 20:43:42 CDT 2003


~sdpm~

>>>>> "Bill" == Bill Wood <wwood at ucsd.edu> writes:

Bill> Can someone help me out. I've got a problem where perl seems to
Bill> be evaluating the test at line 6 below in a string context.

Um.  ">" always does numeric comparisons, which makes me think that I
don't understand exactly what you're doing here.  Do you mean that
you're getting "foo is not numeric in numeric gt" type warnings?

And is this all under "use strict" and -w?

Bill> I'm taking the results of database call to a datediff function
Bill> and doing a greater than test. When the result is negative the
Bill> if branch is still being taken.

Interestingly enough, there is no documented "sql" method in the
generic DBI perldoc; what DBD are you using?

Bill> 1	my $date_diff=0;
Bill> 2	my $diff_test = 0;
Bill> 3	my $sql = qq/
Bill> 4	select datediff(dd,"$last_used_date{$card_key}","$trans_date")/;
Bill> 5	@ret = $dbh->sql("$sql",sub {($date_diff)=@_;});
Bill> 6	if	($date_diff > $diff_test ) {
Bill> 7		$last_used_date{$card_key} = $trans_date;
Bill> 8		}

I'd probably phrase this like so:

| my $res_aref = $dbh->selectall_arrayref( "SELECT datediff( dd, ?, ? )",
|                                          {}, # no attributes
|                                          $last_used_date{$card_key},
|                                          $trans_date );
| 
| my $date_diff = $res_aref->[0][0];
| my $diff_test = 0;
| if ( $date_diff > $diff_test )
| {
|     $last_used_date{$card_key} = $trans_date;
| }

I'm used to Oracle SQL, which would require that we select from the
pseudo-table DUAL to get the results of a function like that:

| my $res_aref = $dbh->selectall_arrayref( "SELECT datediff( dd, ?, ? )" .
|                                          "  FROM DUAL",
|                                          {}, # no attributes
|                                          $last_used_date{$card_key},
|                                          $trans_date );

Which is getting a little out of hand; switching to defining $sql
seperately doesn't seem like a bad idea at this point:

| my $sql = 'SELECT datediff( dd, ?, ? ) FROM DUAL';
| my $res_aref = $dbh->selectall_arrayref( $sql, {}, # no attributes
|                                          $last_used_date{$card_key},
|                                          $trans_date );

If you are going to be doing a lot of these SELECT calls, you should
perhaps perpare it only once, then do the explicit execute / fetch /
finish loop.

Bill> This is perl, version 5.005_03 built for sun4-solaris

Note that this is a relatively ancient version of perl; 5.8.0 is
current (or has 5.8.1 come out?).  Bug your admins to upgrade.

Bill> All comments appreciated, thanks

Just by the by, if you are just trying to compare two date strings,
consider using Date::Parse and Date::Calc instead of making a much
much much more expensive call into the database.

Share and enjoy,
t.
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list