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;