Like I said yesterday, if you don't care about the order in which the values were added (if you are going to sort the output anyway, for example), you can store the $version as hash keys, rather than an array. (This is the rough equivalent of Python's sets, like what you showed us in the CB yesterday). Your structure can by using this statement instead of the push:
. And then you can iterate over it with:$hash->{$value}{$version}++; # The names you used yesterday
The values are stored unsorted, but you can just sort them at the last moment when going through them. You can use Data::Dump (or Data::Peek as pointed by Tux :) ). To see what the content of the $hash looks like.for my $outer (keys %$hash) { my $subhash = $hash->{$outer}; for my $inner (sort { $a <=> $b } keys %$subhash) { # iterating over the sorted values } }
Edit: try to avoid one-letter names, but never use $a outside of sort, as it has a special meaning for that case and some others (like some functions of List::Util)
In reply to Re: Understanding how sort uniq works
by Eily
in thread Understanding how sort uniq works
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |