in reply to Idiom for looping thru key/value pairs

It might be easier to work with the data stored as an array of arrays. eg:
my @data = ( [ 'a', 2 ], [ 'b', 5 ], [ 'b', 2 ], [ 'c', 8 ] ); # Keep data sorted on keys. @data = sort { $a->[0] cmp $b->[0] } @data; # Get list of values in order @values = map { $_->[1] } @data; # Operate on values, in order { $_->[1] =* 2 } foreach ( @data );

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Idiom for looping thru key/value pairs
by petdance (Parson) on May 26, 2001 at 01:09 UTC
    I did originally have them as lists of lists, but flattening out into the "array of key/value pairs" idea sped up my constructor by about 10%, which was pretty significant.

    xoxo,
    Andy

    %_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
    'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
    "hack";print map delete$_{$_},split//,q<   andy@petdance.com   >
    

      Since you already have an object, I'd really encourage you to consider separating them into two separate parallel lists!

              - tye (but my friends call me "Tye")