Just a repost of some code from the search term code I've posted. Easier to find this way. Any hoo, This code takes a hash array, and sorts it, first by the numerical value (in the value) and then alphabetically by key if there are any with the same value. i.e. :
bob=>13
brian=>14
jeff=>13
would become
brian=>14
bob=>13
jeff=>13
Of course, i had to stick it into a couple of arrays, but as long as you pull them with the same index, you'll get the paired data.
#copys the hash array into a pair of arrays.
my @sortedkeys = sort(keys %queryterms);
my $key;
my @array1;
my @array2;
foreach $key (@sortedkeys)
{
push(@array1,$key);
push(@array2,$queryterms{$key});
}
## sort area. sorts the two arrays keeping each pair value together ac
+ross the split.
my $index=0;
my $smallest=0;
my $count=@array1;
my $x;
for ($x=($count-1);$x>0;$x--){
$smallest=$x;
#Find the smallest element with this
for ($index=0;$index<=$x;$index++)
{
next if ($array2[$smallest] < $array2[$index]);
next if (($array2[$smallest] == $array2[$index]) && (uc($array
+1[$smallest]) gt uc($array1[$index])));
$smallest=$index;
}
#swap the smallest and the top element
if ($x != $smallest){
($array1[$smallest],$array1[$x])=($array1[$x],$array1[$smalles
+t]);
($array2[$smallest],$array2[$x])=($array2[$x],$array2[$smalles
+t]);
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.