<?xml version="1.0" encoding="windows-1252"?>
<node id="767988" title="Loosing Negative Values in Array Ref" created="2009-06-03 08:44:11" updated="2009-06-03 08:44:11">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
Hi Monks!&lt;br&gt;

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?&lt;br&gt; 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:&lt;br&gt;&lt;br&gt;
&lt;p&gt;
&lt;readmore&gt;
&lt;code&gt;
#!/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-&gt;[0];
    
    push @{$acc_num-&gt;{$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-&gt;[$i] = $aref-&gt;[$i];
        }
        
        for my $i (2..$#$aref) {
        
            $tmp-&gt;[$i] = '0' unless defined $tmp-&gt;[$i]; # for 'use warnings'
            
            # Need to check for numeric or string values here:::
            if($tmp-&gt;[$i]=~m/^[+-]?\d+$/){
            
            $tmp-&gt;[$i] = $aref-&gt;[$i] if $aref-&gt;[$i] gt $tmp-&gt;[$i];
            
            #}elsif($tmp-&gt;[$i]=~m/^[+-]?\w+$/){
            
            #$tmp-&gt;[$i] = $aref-&gt;[$i] if $aref-&gt;[$i] gt $tmp-&gt;[$i];
            
            }else{
            
            $tmp-&gt;[$i] = $aref-&gt;[$i] if $aref-&gt;[$i] gt $tmp-&gt;[$i];
            
            }
            # End checking for numeric or string values.
        }        
        
    }
}


print Dumper $all_dta_acc_num;

&lt;/code&gt;
&lt;/readmore&gt;
&lt;/p&gt;
&lt;br&gt;
Thank you!</field>
<field name="reputation">
8</field>
</data>
</node>
