I looked over what you have and you are doing some dangerous scoping with the code you have posted. I see where you are coming from and hopefully what I post will push you in the right direction.

1. use strict, please read up on this module it is really important since it can help you find many of your errors.
2. Use gobal variables with caution.
3. Pass your data as a reference to your sub routines and scope them inside of the subroutines.
You didn't post all of your ListDados sub, but I do you are calling it on what is scoped as a global. Here is how I would write the top part of your code:
# your original queries format odd so I adjusted it slightly # think this may also be the source of your results # being duplicated my $sth = $dbh->prepare_cached(qq!SELECT DISTINCT A.p_code, A.business, A.status, A.value, A.login, A.e +nc_date, B.name, B.state FROM business A, users B WHERE A.login = ? AND A.data_enc_proposta = ? ORDER BY A.login, A.data_enc_proposta!); } $dbh = SysUtils::Connect; # $login_value and $data_enc_value have to come # from somewhere. $sth->execute($login_value,$data_enc_value); while (my ($rs,$neg,$st,$vp,$gel,$dte,$gen,$fil) = $sth->fetch +row_array()) { my $hashref = { $fil => { $gel => { $dte => { cliente => "$rs", negocio => "$neg", status => "$st", valor => "$vp", nome => "$gen" } } } } ); ListaDados($hashref); }
Then inside of your ListDados I would have something like this:
sub ListDados { my ($dados) = @_; foreach (keys %{$dados}) { $vf = "R\$ "; $tf = "R\$ "; $dados->{$fil}{$gel}{$dte}{valor} =~ s/\.0000$/\,00/; $vf .= $dados->{$fil}{$gel}{$dte}{valor}; if ($cnt eq 0) { $message .= qq!<TR class="texto3"> <TD colspan="4" BGCOLOR="$color2"><span class ="texto2">$dados->{$fil} +{$gel}{$dte}{nome}</span></TD> </TR> <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0"> <TR CLASS="texto2"> <TD>Client</TD> <TD>Business</TD> <TD>Status</TD> <TD>Value</TD> </TR> <TR> <TD COLSPAN="4"> <HR> </TD> </TR> <TR CLASS="texto3"> <TD BGCOLOR="$color2">$dados->{$fil}{$gel}{$dte}{cliente}</TD> <TD BGCOLOR="$color2">$dados->{$fil}{$gel}{$dte}{negocio}</TD> <TD BGCOLOR="$color2">$dados->{$fil}{$gel}{$dte}{status}</TD> <TD BGCOLOR="$color2">$vf</TD> </TR>!; $cnt++; ($color2,$color1) = ($color1,$color2); } else { $message .= qq!<TR CLASS="texto3"> <TD BGCOLOR="$color2">$dados->{$fil}{$gel}{$dte}{cliente}</TD> <TD BGCOLOR="$color2">$dados->{$fil}{$gel}{$dte}{negocio}</TD> <TD BGCOLOR="$color2">$dados->{$fil}{$gel}{$dte}{status}</TD> <TD BGCOLOR="$color2">$vf</TD> </TR>!; ($color2,$color1) = ($color1,$color2); } } }
This is just some of the things you can do to clean it up.

NOTE: not throughly proofread, please CB me on any errors and I correct them.

In reply to Re: Probelms returning values from a db and putting into a hash by trs80
in thread Problems returning values from a db and putting into a hash by DaWolf

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.