in reply to sort and hash
Let's say you have a hash like so:
You can add more key/value pairs like so:my %sequence = ( 1345 => 10, 123 => 20, 500 => 30, );
Let's say that your id is stored in the variable $id and the score is stored in the variable $score. You can add this information to the hash like so:$sequence{901} = 40;
If you want to sort the data by say, the id, you can get a list of the keys with the keys built-in function and use the sort built-in function, specifying that you want to sort numerically with the "spaceship" operator <=> like so:$sequence{$id} = $score;
Perl's motto is 'There Is More Than One Way To Do It'. Give us some more context, like what these id's and scores really look like and we can help even more.print "$_ => $sequence{$_}\n" for sort {$a<=>$b} keys %sequence;
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: sort and hash
by kaweh (Initiate) on Sep 22, 2003 at 23:14 UTC | |
by jeffa (Bishop) on Sep 23, 2003 at 00:51 UTC |