robsv has asked for the wisdom of the Perl Monks concerning the following question:
I am calling an external routine which returns a string containing 2, 3, or 4 letters in the order in which they are read. I need to sort this string before outputting it. For example, if $bases = 'GCT', I need to change $bases to 'CGT' (the fine print: I'm playing with DNA, so the alphabet is 'ATCGN').
I'm currently doing this:
- robsv
...which seems like a bit of overkill if the string will always be 2-4 characters. Since There's More Than One Way To Do It, I was wondering what other ways there were to do it. (This isn't meant to be a Golf question, but golfers are welcome!)$bases = join '',sort split('',$bases);
- robsv
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting characters within a string
by kjherron (Pilgrim) on Aug 24, 2001 at 04:13 UTC | |
by jlongino (Parson) on Aug 24, 2001 at 05:05 UTC | |
by tilly (Archbishop) on Aug 24, 2001 at 06:02 UTC | |
by guillaume (Pilgrim) on Aug 24, 2001 at 05:45 UTC | |
by jlongino (Parson) on Aug 24, 2001 at 05:55 UTC | |
by jlongino (Parson) on Aug 24, 2001 at 05:33 UTC | |
by dga (Hermit) on Aug 24, 2001 at 23:42 UTC | |
Re: Sorting characters within a string
by clintp (Curate) on Aug 24, 2001 at 05:06 UTC |
Back to
Seekers of Perl Wisdom