Alright, so I have a question for all you Perl gurus out there... I have a program that yields a set of data, in a certain format. The program is written in Perl, and I would like to append some code to the program that will sort the data it produces a certain way. Here is what the original output looks like:
ALPHA:D 20 letters ABCCEDFFGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFFGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFGGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFGGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFGGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFGGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFFGAACDDEEEEFG ALPHA:D 20 letters ABCCEDFFGAACDDDEEEFG ALPHA:D 20 letters ABCCEDFFGAACDDEEEEFG ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAD ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAD ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAD ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAD ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAD ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE
Each field is tab-delimited (except for the space between "20" and "letters", for example, which is just a space). I'm looking for a few lines of code that will sort the data so that it looks like this:
ALPHA:D 20 letters ABCCEDFGGAACDDDEEEFG 4 ALPHA:D 20 letters ABCCEDFFGAACDDDEEEFG 3 ALPHA:D 20 letters ABCCEDFFGAACDDEEEEFG 2 ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAE 7 ALPHA:E 24 letters ABCCEDFFGAACDDDEEEFGAGAD 5
As you can see, what it's doing is looking at each value (e.g., "D" or "E") listed next to the initial name ("ALPHA", in this case), and counting the number of unique arrangements of letters for that specific value. Please note that while a line may contain the same number of letters (e.g., "20 letters"), it may not have the same arrangement. Certain letters might be different in the string. For value "D", the arrangement "ABCCEDFFGAACDDDEEEFG" appears 3 times, but not necessarily in order. The arrangement "ABCCEDFGGAACDDDEEEFG" appears 4 times. The code should get the counts, order them with the highest counts first, then move to the next value. I am assuming that there are some really basic string manipulation commands that can do this quite easily, but I am by no means an expert in Perl, so I have no idea how this would work. Could any of you help me out here? I would greatly appreciate it!
In reply to String sorting in Perl by markdavis87
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |