http://qs321.pair.com?node_id=207279


in reply to Changing Perl's sort Default

Hi @rocks,

The sort function has two modes. One is numeric sort and the other is lexical sort. An example of each is below:

#!/usr/bin/perl -w use strict; my @array = ( 2, 5, 17, 1, 28, 30, 100, -1 ); my @array2 = ( 'x', 'v', 'z', 'p', 'a', 'b' ); my @array_sorted = (); my @array2_sorted = (); @array1_sorted = sort { $a <=> $b } @array; @array2_sorted = sort { $a cmp $b } @array2; print "@array1_sorted\n"; print "@array2_sorted\n"; __OUTPUT__ C:\perl>perl p5.pl -1 1 2 5 17 28 30 100 a b p v x z C:\perl>

Hope this helps,
-Katie.

Replies are listed 'Best First'.
Re: Re: Changing Perl's sort Default
by @rocks (Scribe) on Oct 23, 2002 at 03:34 UTC
    Katie, I think you misunderstood my question. I wanted to know if there was a to change the default of perl's sort command structure to AlphaNumerical or any other custom setting.

    -@rocks