in reply to Combining Duplicate entries in an Array

This may be easier done with a hash, and that way it also doesn't matter if the "duplicates" come right after each other. Pseudo-code:

create a hash foreach key and value pair in 2d array drop .\d from key if key exists in hash increase the key's value by the current value from array else add current key/value to hash loop through hash, printing keys and values

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Replies are listed 'Best First'.
Re^2: Combining Duplicate entries in an Array
by mmartin (Monk) on Feb 22, 2012 at 20:36 UTC
    Hey Aaron, thanks for the reply.

    My experience with hashes is limited, that's why I decided to go with an array to do this stuff.
    But that array is one of about 5 total arrays that contain info like that. But my end result will be a hash with all 5 arrays combined using the "ID" as a key.

    I've already been able to combine those arrays into a hash, I just had to get rid of those "Duplicates" first cause it can get pretty confusing with a hash and all the brackets..

    But thanks again,
    Matt