in reply to criteria based array sorting

A wee Schwartzian transform should do it
my @unsorted = qw/Psdf lPik Easd aKwe SSdf eqwer scfgh Oegb rqwer T/; print "pre sorted: @unsorted\n"; my @sorted = map substr($_, 1), sort map { /^[a-z]/ ? "A$_" : "B$_" } @unsorted; print "post sorted: @sorted\n"; __output__ pre sorted: Psdf lPik Easd aKwe SSdf eqwer scfgh Oegb rqwer T post sorted: aKwe eqwer lPik rqwer scfgh Easd Oegb Psdf SSdf T
See. japhy's Resorting to Sorting for more information on Schwartzian transforms and other sorting techniques.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: criteria based array sorting
by hardburn (Abbot) on Feb 12, 2004 at 20:34 UTC

    That's not a Schwartzian Transform, but a GRT. The code is structurally similar, but works slightly differently. Though some consider the GRT to be a subset of the ST, this is a matter of debate.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      hardburn,
      Actually it is a variation on the GRT that tye likes to call The One True Sort. The subtle difference is that you do not have to restore the transformation - you can simply throw it away. An example of a classicle GRT would be:
      #!/usr/bin/perl use strict; use warnings; my @needs_sorting = qw(Psdgs ldfgs Esdds aSdg Sgsdfs esdf sgfsdfg Osgr + T); @needs_sorting = map { /^[a-z]/ ? "\u$_" : "\l$_" } sort map { /^[a-z]/ ? "\u$_" : "\l$_" } @needs_sorting; print "$_\n" for @needs_sorting;
      Cheers - L~R
        Actually it is a variation on the GRT that tye likes to call The One True Sort.
        Actually it's not. The One True Sort sorts array indices.
        What we have here is a run-of-the-mill GRT. Which, btw, is a sub-species of the ST. No debate about it. :-)

        jdporter
        The 6th Rule of Perl Club is -- There is no Rule #6.