Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
<edit> Looks like I need an array of hashes, because the records were getting overwritten. But doing something like this will screw up the JSON:
$counter++; $hashData{$counter}{'id'} = $hold_col_val1; $hashData{$counter}{'col2'} = $hold_col_val2; $hashData{$counter}{'col3'} = $hold_col_val3; $hashData{$counter}{'col4'} = $total_cdr_count; $hashData{$counter}{'col5'} = $total_call_count; $hashData{$counter}{'col6'} = $total_error_count; push @output, \%hashData;
I appreciate your help with all of this. I haven't touched perl in a while and trying to get the hash to work. I comes out like this now, and the extra digit at the beginning of every record. Can it be removed before encoding it in JSON?
$sth->execute(); while (my $row = $sth->fetchrow_hashref ){ push @newRow, $row; $gt_cdrs = $gt_cdrs + $row->{"col4"}; $gt_hold_time=$gt_hold_time + $row->{"col5"}; if ($row->{"CALL_STATUS"} eq "S" || $row->{"CALL_STATUS"} eq " +R" || $row->{"CALL_STATUS"} eq "I") { $gt_duration = $gt_duration + $row->{"col6"}; } else { $gt_errs = $gt_errs + $row->{"col4"}; } $gt_calls = ($gt_cdrs - $gt_errs); ################################# if (($hold_col_val1 ne $row->{"id"}) || ($hold_col_val2 ne $row->{"co +l2"}) || ($hold_col_val3 ne $row->{"col3"})) { unless ($hold_col_val1 eq "~~~") { ## calculate percentages $ASR = (($total_cdr_count-$total_error_count) +/ $total_cdr_count) * 100; if (($total_cdr_count-$total_error_count) > 0) + { $avgPDD = $good_hold_time / ($total_cd +r_count - $total_error_count); $avgDUR = $good_duration / ($total_cdr +_count - $total_error_count); } else { $avgPDD = 0; $avgDUR = 0; } $minutes = $good_duration / 60; if($asr_scrn ne "") { if( ($asr1 ne "" ) && ($asr2 eq "") ) +{ if ($ASR > $asr1) { goto EXTCHK1; } } if( ($asr1 ne "" ) && ($asr2 ne "") ) +{ if ( ($ASR < $asr1 ) || ($ASR +> $asr2+1) ) { goto EXTCHK1; } } } $formatASR = sprintf("%3.0d",$ASR); $formatPDD = sprintf("%3.0d",$avgPDD); $formatDUR = sprintf("%3.0d",$avgDUR); $formatMin = sprintf("%4.1f",$minutes); } $counter++; $hashData{'counter'} = $counter; $hashData{$counter}{'id'} = $hold_col_val1; $hashData{$counter}{'col2'} = $hold_col_val2; $hashData{$counter}{'col3'} = $hold_col_val3; $hashData{$counter}{'col4'} = $total_cdr_count; $hashData{$counter}{'col5'} = $total_call_count; $hashData{$counter}{'col6'} = $total_error_count; push @output, \%hashData; #print $hashData[$counter]{'id'}." ".$hashData[$counte +r]{'col6'}."\n"; }

In reply to Re^6: JSON module by hallikpapa
in thread JSON module by hallikpapa

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-19 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found