in reply to criteria based array sorting

Yet another approach to the first part:

@sorted = sort { substr($a, 0, 1) cmp substr($b, 0, 1) || lc($a) cmp lc($b) } @needs_sorting;

Hugo

Replies are listed 'Best First'.
Re: Re: criteria based array sorting
by Roy Johnson (Monsignor) on Feb 12, 2004 at 21:00 UTC
    That's not quite right: your method sorts case-sensitively (uppercase first) on the first letter, and otherwise sorts case-insensitively. Whether the OP wanted the sort to be otherwise case-insensitive is not clear, but he did ask for lowercase initial letters to be first.

    Here's a fix:

    sort { $b=~/^[a-z]/ <=> $a=~/^[a-z]/ or lc($a) cmp lc($b) }

    The PerlMonk tr/// Advocate