Hi Monks!

I am having an issue here that I can't think how to solve it, the problem is that the result(s) back from this code is not return the sum I am expecting, I found by running the commented test code on code that the value for $type "W" is been returned with an extra space after the W, like: $VAR1 = [ [ 'W ', '4' ] ]; as you can see here.
How could I remove any extra spaces before they reach the line
my $array_ref = $sth->fetchall_arrayref(); or any other solution to prevent that.

Thanks for the help!!!
.... my $sth = $dbh->prepare($sql); $sth->execute() || die $sth->errstr; #test values here::: #use Data::Dumper; #my $array_ref = $sth->fetchall_arrayref; #print Dumper $array_ref; #end test::: my $array_ref = $sth->fetchall_arrayref(); foreach $row (@$array_ref) { ($type, $total) = @$row; if ($type eq "A"){$a = $total;} if ($type eq "B"){$b = $total;} if ($type eq "C"){$c = $total;} if ($type eq "D"){$d = $total;} if ($type eq "W"){$w = $total;} } $total = $a + $b + $c + $d + $w; print "$w\n"; print "$total\n";

In reply to Extra Space Issue by Anonymous Monk

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.