Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi Monks!
I am combining the elements of the array here on my code sample to get the unique one to my report, but what is happening is that I am loosing the negative values that is part of the unique array, I can't understand why it is happening, can someone help with that?
Just one more question, how would I get my results in alphabetic order, just in case someone has done that before. Here is the code:

#!/usr/bin/perl use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI ':standard'; use Data::Dumper; my $test_array_ref = [ [ 'Amber Benedit C', '23455443', '2008-01-11', 'X', '11', '0', '7.00', ' ', '2', '2', '3', ' ', '-2.0', ' ', ' ', ' ', ' ', ' ', ' ', '3.0', '2008', '1112399' ], [ 'Amy Israel D', '22345666', '2008-03-04', 'X', '999', '0', '8.00', ' ', '0', '2', '0', ' ', '-5.00', ' ', ' ', ' ', ' ', ' ', ' ', '2.0', '2008', '1112399' ], [ 'Auser Ferro', '987778999', '2008-11-30', 'W', '200', '0', '0', ' ', '1', '2', '4', ' ', '-5.00', ' ', ' ', ' ', ' ', ' ', ' ', '2.0', '2008', '1112399' ], [ 'Auser Ferro', '987778999', '2008-11-30', 'W', '888', '0', '0', ' ', '1', '2', '4', ' ', '-5.00', ' ', ' ', ' ', ' ', ' ', ' ', '2.0', '2008', '1112399' ], [ 'Yuong John', '22357790', '2008-03-27', 'W', '50', '0', '4.00', ' ', '4', '2', '3', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', '3.0', '2008', '1112399' ], [ 'Zilda Mil', '88997665', '2008-05-12', 'W', '999', '0', '4.00', ' ', '0', '2', '3', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', '14.0', '2008', '1112399' ], [ 'Zilda Mil', '88997665', '2008-05-12', 'X', '999', '0', '4.00', ' ', '1', '2', '3', ' ', '-8.00', ' ', ' ', ' ', ' ', ' ', ' ', '9.0', '2008', '1112399' ] ]; ## TEST FOR UNIQUE VALUES # Group arrays by account number + higher elements in the array my $acc_num = {}; for my $aref (@$test_array_ref) { my $uniq_key = $aref->[0]; push @{$acc_num->{$uniq_key}}, $aref; } my $all_dta_acc_num = []; for my $aref_acc_num (values %$acc_num) { push @$all_dta_acc_num, my $tmp = []; for my $aref (@$aref_acc_num) { for my $i (0..1) { $tmp->[$i] = $aref->[$i]; } for my $i (2..$#$aref) { $tmp->[$i] = '0' unless defined $tmp->[$i]; # for 'use war +nings' # Need to check for numeric or string values here::: if($tmp->[$i]=~m/^[+-]?\d+$/){ $tmp->[$i] = $aref->[$i] if $aref->[$i] gt $tmp->[$i]; #}elsif($tmp->[$i]=~m/^[+-]?\w+$/){ #$tmp->[$i] = $aref->[$i] if $aref->[$i] gt $tmp->[$i]; }else{ $tmp->[$i] = $aref->[$i] if $aref->[$i] gt $tmp->[$i]; } # End checking for numeric or string values. } } } print Dumper $all_dta_acc_num;


Thank you!

In reply to Loosing Negative Values in Array Ref 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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (3)
    As of 2014-10-25 01:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (139 votes), past polls