Thanks For the quick response. To simplify my question I used an array as an example.

Can I use the same concept on a hash value? Let's say I want to perform the same operation on values of the hash and return the sorted keys with new data. For instance:

#!/usr/local/bin/perl use strict; my %pvalues = ( 1=> 0.5453980, 2=> 0.4902384, 3=> 0.8167950, 4=> 0.2821822, 5=> 0.4693030, 6=> 0.6491767, 7=> 0.9802138, 8=> 0.1155778, 9=> 0.9585124, 10=> 0.4069490 );

They keys of course are unique but the values may not. I have done the following.

my $numberPvalues = scalar keys %pvalues; my $numberPvaluesCounter = scalar keys %pvalues; my $numberPos = 0; # now loop through all p values and calculate FDR value # store FDR values in hash, key = pos, value is FDRq my @reversPvalues =(); my %sortedTransfPvalues =(); my @inversPvalue =(); my @cumulminPvalue =(); while ($numberPvaluesCounter >= 1 ){ #Sort the original pvalue hash based on the values descen +ding manner foreach my $posCurrentPvalue (sort {$pvalues{$b} <=> $pva +lues{$a}} keys %pvalues) { #calculate the transformed pvalues based on its rank + in the sorted value in the hash my $transformedPvalue = $pvalues{$posCurrentPvalue} +* $numberPvalues / $numberPvaluesCounter; $numberPvaluesCounter--; #new indcies $numberPos++; push (@inversPvalue, $transformedPvalue); #$sortedTransfPvalues{$numberPos}{$posCurrent +Pvalue} = $transformedPvalue; #$sortedTransfPvalues{$posCurrentPvalue}{$num +berPos} = $transformedPvalue; print "$posCurrentPvalue\t$transformedPvalue\ +n"; }#end foreach and sorting values }#end while for count down

In reply to Re^2: Restore the original order of an array after sort and performing some funchtion on array values by sesemin
in thread Restore the original order of an array after sort and performing some funchtion on array values by sesemin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.