Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Changing Perl's sort Default

by DigitalKitty (Parson)
on Oct 23, 2002 at 03:30 UTC ( #207279=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://207279]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-12-06 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?