Phoenix.pm: sort function
Anthony R. Nemmer
edelsys at swlink.net
Wed Jun 9 03:13:10 CDT 1999
At 12:56 AM 6/9/99 -0700, you wrote:
>What do I need to do, in order to sort a hash, ignoring the case of the
>letters?
>
>I have a foreach statement like this:
> foreach $var (sort keys (%CAT) ) {
>
>The results of this sort, give me all the listings that start with capital
>A-Z, *then* all the listings that start with lowercase a-z. Of course, I
>want to sort based on Aa-Zz (or, aA-zZ).
>
>Thanks.
>
Give this a try:
%foo = ( "Iota" => "blah",
"iota" => "blahblah",
"Beta" => "yech",
"betadyne" => "ouch!",
"baabaa" => "sheep sounds",
"Gamma" => "rays",
"globulin" => "sticky",
"Gerber" => "pablum" );
foreach ( sort smashcase(keys(%foo)) ) { print("$_\n"); }
sub smashcase { lc($a) cmp lc($b); }
exit(0);
The results are:
baabaa
Beta
betadyne
Gamma
Gerber
globulin
Iota
iota
Tony
--
-- Anthony R. Nemmer EdelSys Consulting
-- edelsys at edelsys.com http://www.edelsys.com/ ICQ #14638605
-- (480) 967 - 8302 P.O. Box 1883, Tempe, Arizona 85280-1883
--
-- Opera r0ks! ==> http://www.operasoftware.com/
-- HotJava 3.0 r0ks too! ==> http://java.sun.com/products/hotjava/3.0/
--
More information about the Phoenix-pm
mailing list