Here's a simplistic mechanism that would probably benefit from using a GRT. It relies upon having a pre-ordered lookup table, here in the form of a simple space delimited string and the ordering is performed by the simple numerical comparision of the target position within the string.
#! perl -slw use strict; my $order = 'N CA C O CB CG CD1 CD2 CE1 CE2 CZ OH 2HB 3HB HD1 HD2 HE1 +HE2 HH'; my @unordered = qw[ 2HB 3HB C CA CB CG CD1 CD2 CE1 CZ CE2 HE2 HE1 HH H +D1 HD2 N O OH ]; print join' ', sort{ index( $order, $a ) <=> index( $order, $b ) } @un +ordered; __END__ P:\test>295668 N C CA O CB CG CD1 CD2 CE1 CE2 CZ OH 2HB 3HB HD1 HD2 HE1 HE2 HH
However, I suspect that you would like to not have to pre-construct the ordering of all possible compounds but would prefer their "weight" to be calculated according to your set of rules. That would be possible to do using a lookup hash mapping the symbols to weights and the some math to multiply by the number of hydrogens (terminology?).
To code this would require a clearer set of rules to work with. The only minor problem I see is parsing combined symbols -- do CA, CB, CD, CE, CZ break down into "C & A", "C & B"... etc. or are they intrinsic, but that is easily summountable.
In reply to Re: sorting according to greek alphabet in roman letters
by BrowserUk
in thread sorting according to greek alphabet in roman letters
by seaver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |