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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|