in reply to Sorting issue

Clearly what you need is a "custom sort" criteria block. So instead of just sort keys %tag as your code above has it, you can do something like this:

foreach my $tags ( sort { (split /,/,$a)[1] <=> (split /,/,$b)[1] } keys %tag ) {

Of course, this could be optimized, and that might be important if your input file is huge.

I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Replies are listed 'Best First'.
Re^2: Sorting issue
by bluray (Sexton) on Nov 05, 2011 at 01:35 UTC
    Hi jdporter,

    I have tried the custom sort previously. But it gave the error message "Use of uninitiated value.. " for each line. So, I checked the input file for repeats in the frequency column and it is repeated. I guess, there will be a clash in the way hash stores each values. In the first column of output file, I also concatenated the tag column (first column of input file) to make it unique. Now, I am thinking of sorting with respect to the first column of output file. So far, not successful. Currently, my output file look like this:

    Header Tags Frequency >HWTI_2_78439EEEEEMMMMMG EEEEEMMMMMG 2 >HWTI_3_338554FFEFFFDFEMM FFEFFFDFEMM 3 -------------------------------------------

      Duplicate values in a hash aren't a problem; only duplicate keys are. So if your tags are never repeated, you'll be fine putting each input line's tag as the hash key and the frequency as its value.

      When it comes time to sort, you can only sort your hash on something that's in your hash. So if your hash contains the tags and frequencies, you can sort on either of those (see my last reply for how to sort on the values); but you can't sort on the header that you haven't created yet.

        The keys (tags) are unique.