Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Loosing Negative Values in Array Ref by Marshall
in thread Loosing Negative Values in Array Ref by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found