in reply to Chomp Maybe?
When using DBI and prepare, use placeholders. If you don't know what they are, read the doc. To put it simply, you can put a ? in the prepare statement, pass values for each in the execute, and it will properly quote it for you. In your case, something like this
would work. This is good for untrusted data.my $dbh = $db->prepare("SELECT balance FROM Table1 WHERE username=? an +d balance < '-.01'"); $dbh->execute($authuser); my ($balance_due) = $dbh->fetchrow_array;
Anyway, the easiest solution to your problem would be to simply negate the value, which would yield a positive. So something like
would be good and result in $balance_due being equal to 9.99.$balance_due = -$balance_due # or $balance_due = $balance_due * -1;
To answer your question using a different way, you could also use a substitution regex
to strip out (literally replace it with nothing) the first - it finds. If you don't understand what it going on, read up on perlretut.$balance_due =~ s/-//;
Added Second paragraph.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Chomp Maybe?
by hardburn (Abbot) on Jul 01, 2003 at 18:24 UTC | |
by The Mad Hatter (Priest) on Jul 01, 2003 at 18:32 UTC | |
|
Re: Re: Chomp Maybe?
by th3monk3y (Novice) on Jul 01, 2003 at 04:52 UTC |