in reply to Why do we need $a and $b to be special?
$mol->sort_atoms($sub_ref)Sort the atoms in the molecule by using the comparison function given in $sub_ref. This function should take two atoms as parameters and return -1, 0, or 1 depending on whether the first atom should go first, same, or after the second atom. For example, to sort by atomic number, you could use the following:
$mol->sort( sub { $_[0]->Z <=> $_[1]->Z } );
Note that the atoms are passed as parameters and not as the package variables $a and $b like the core sort function does. This is because $mol->sort will likely be called from another package and we don't want to play with another package's symbol table.
|
|---|