http://www.perlmonks.org?node_id=862117


in reply to transforming XY data to X and Multiple Y column data?

You could try a more complex data structure.

A something of somethings of arrays should do the trick, such as an array of arrays of arrays:-

@id = ( [ [ ], # id1-0 [ ], # id2-0 [ 0, 0, 0 ], # id3-0 ], [ [ 90, ], # id1-1 [ 70, ], # id2-1 [ ], # id3-1 ], # ... );

...or an array of hashes of arrays:-

@id = ( { id3 => [ 0, 0, 0 ], }, { id1 => [ 90, ], id2 => [ 70, ], }, # ... );

...or even a hash of hashes of arrays:-

%id = ( 0 => { id3 => [ 0, 0, 0 ], }, 1 => { id1 => [ 90, ], id2 => [ 70, ], }, # ... );

Without knowing more about your input data, it's hard to say which of those will best suit your needs (or if something else is more appropriate or possible), but the of arrays part will at least do away with the issue of duplicates.

    --k.


Edit: Fixed typos in examples.