Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I can think of a couple other ways to do it, but they're both worse than yours unless you're having performance problems:
1) Generate every possible string and its sorted version, storing them in a hash with the unsorted string as the key & the sorted string as the value. There's only, what, 45 possible strings? That's doable. 2) Split the string into characters, count the number of each character, then output the characters in order based on the counts. This is O(n) so it'd be a win if your strings were really long, but it's just overkill for these short strings. If performance is a problem, a fairly painless thing to do is cache the sorted strings as you calculate them: This is of course just a lazy variant on #1 above. In reply to Re: Sorting characters within a string
by kjherron
|
|