A couple points:

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

my $dbh = $db->prepare("SELECT balance FROM Table1 WHERE username=? an +d balance < '-.01'"); $dbh->execute($authuser); my ($balance_due) = $dbh->fetchrow_array;
would work. This is good for untrusted data.

Anyway, the easiest solution to your problem would be to simply negate the value, which would yield a positive. So something like

$balance_due = -$balance_due # or $balance_due = $balance_due * -1;
would be good and result in $balance_due being equal to 9.99.

To answer your question using a different way, you could also use a substitution regex

$balance_due =~ s/-//;
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.

Added Second paragraph.


In reply to Re: Chomp Maybe? by The Mad Hatter
in thread Chomp Maybe? by th3monk3y

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.