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

Re: Loosing Negative Values in Array Ref

by Marshall (Prior)
on Jun 04, 2009 at 15:23 UTC ( #768470=note: print w/ replies, xml ) Need Help??


in reply to Loosing Negative Values in Array Ref

I took at a stab at coding this thing. I don't know if this helps or not, you may find the function anyCompare useful...Could be some problems with this code...Dunno..its early in the morning here...

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


Comment on Re: Loosing Negative Values in Array Ref
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://768470]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-09-19 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (131 votes), past polls