Well, that’s a very clumsy data structure you have there. And the code is clumsier than it needs to be, on top of that. What’s that count doing? Looks like a no-op to me. And don’t use for(;;), use for(@LIST):
for my $i ( 0 .. $#{ $self->{ keys } } ) { my $id = $self->{ keys }->[ $i ]; # ... }
You could write accessor methods for that part of the data structure so you could say something like:
for my $i ( 0 .. $self->max_index() ) { my ( $key, $value ) = $self->at( $i ); # ... }
Or maybe an iterator would be better?
my $iter = $self->iterator(); while( my ( $key, $value ) = $iter->() ) { # ... }
Or you could use one of the modules that implement ordered hashes, such as Tie::IxHash, which will let you write this directly using keys and friends.
Lots of options that depend on what you want to do; for laziness, the tied hash is hard to beat.
Makeshifts last the longest.
In reply to Re: "array" search
by Aristotle
in thread "array" search
by Sheol
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |