my $test_array_ref = [ [ 'Amber Benedit C', '23455443', '2008-01-11', 'X',.... ....... like in your post........ ]; my %accountNames =(); foreach my $record_ref (@$test_array_ref) { my ($name, @new_data) = @$record_ref; if (exists $accountNames{$name}) { my @current_data = @{$accountNames{$name}}; my $i =0; foreach my $new_thing (@new_data) { if (anyCompare($new_thing,$current_data[$i])>0) {$current_data[$i]= $new_thing}; $i++; } @{$accountNames{$name}}=@current_data; } else { $accountNames{$name} = [@new_data]; } } foreach my $name (sort keys %accountNames) { print "NAME=$name\n"; print join ("\n", map{/^\s*$/ ? '""' : $_} @{$accountNames{$name}}),"\n"; print "\n"; } sub anyCompare #returns <0,0,>0 like normal <=> or cmp { my ($a,$b) = @_; if ( isNumeric($a) && isNumeric($b) ) {return $a <=> $b} return ($a cmp $b) } sub isNumeric #returns True/False { my $string = shift; my $isNumeric = ($string =~ m/^[-+]*\d+(\.\d+)?$/); return $isNumeric; } __END__ prints: NAME=Amber Benedit C 23455443 2008-01-11 X 11 0 7.00 "" 2 2 3 "" -2.0 "" "" "" "" "" "" 3.0 2008 1112399 NAME=Amy Israel D 22345666 2008-03-04 X 999 0 8.00 "" 0 2 0 "" -5.00 "" "" "" "" "" "" 2.0 2008 1112399 NAME=Auser Ferro 987778999 2008-11-30 W 888 0 0 "" 1 2 4 "" -5.00 "" "" "" "" "" "" 2.0 2008 1112399 NAME=Yuong John 22357790 2008-03-27 W 50 0 4.00 "" 4 2 3 "" 0 "" "" "" "" "" "" 3.0 2008 1112399 NAME=Zilda Mil 88997665 2008-05-12 X 999 0 4.00 "" 1 2 3 "" 0 "" "" "" "" "" "" 14.0 2008 1112399
In reply to Re: Loosing Negative Values in Array Ref
by Marshall
in thread Loosing Negative Values in Array Ref
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |