Ok, that helps. If the tags in your input file are guaranteed to be unique, it's easy. Put them in a hash with the frequencies as the values, and then sort on the values. In this example, %tags is the hash that stores the tags and their corresponding values, and then it's sorted on the values numerically, largest to smallest. The sub make_unique_string() creates the unique key for your output file from the tag and freq.
my %tags; while(<$input_file_descriptor>){ # do stuff to skip headers and blank lines chomp; my( $tag, $freq ) = split /\s+/; $tags{$tag} = $freq; } for my $tag (sort { $tags{$b} <=> $tags{$a} } keys %tags ){ my $freq = $tags{$tag}; # to clarify things below my $unique_string = make_unique_string($tag, $freq); print ">$unique_string\t$tag\t$freq\n"; }
In reply to Re^3: Sorting issue
by aaron_baugher
in thread Sorting issue
by bluray
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |