わかりやすいソート (Re: [Tokyo.pm] Re: [Tokyo.pm] JUS感想 )
maeda @ src.ricoh.co.jp
maeda @ src.ricoh.co.jp
1999年 10月 6日 (水) 19:51:18 CDT
$BA0ED(B@$B%j%3!<$G$9!#(B
$B0pMU$5$s(B> $B0pMU$G$9!#$3$3$G$O$O$8$a$^$7$F$G$9!#(B
$B$"$j$c!"F~$C$F$$$J$$$N$+$H;W$C$F$$$^$7$?!#$h$&$3$=!#(B
$B0pMU$5$s(B> my %cmpstr;
$B0pMU$5$s(B> @sorted = sort {
$B0pMU$5$s(B> ($cmpstr{$a} ||= make_comparison_string($a)) cmp
$B0pMU$5$s(B> ($cmpstr{$b} ||= make_comparison_string($b)) } @unsorted;
$B0pMU$5$s(B> # $B$3$N$^$^$@$H(Bmake_comparison_string$B$,(B0$B$d(B""$B$r$+$($9$H$^$:$$!JM>J,$K(B
$B0pMU$5$s(B> # $BI>2A$9$k!K$G$9$,!"(Bexists$B$r$D$+$C$F$+$1$PHr$1$i$l$^$9(B
exists$B$r;H$C$?Nc$,(BTPJ#14$B$K$"$j$^$9$M!#%9%Z%$%s8l$N<-=q=g%=!<%H$N(B
$BOC$G$9!#(B
$B0pMU$5$s(B> # $B9M$(J}$K47$l$F$7$^$($P!"(BSchwartzian Transform$B$b$=$s$J$K(B
$B0pMU$5$s(B> # $B%H%j%C%-!<$G$b$J$$$H;W$&$s$G$9$1$I(B...
$B$F$$$&$+!"(Blisp$B$d(Bscheme$B$G0i$C$??M$K$O(BSchwartzian Transform$B$C$F%H(B
$B%j%C%-!<$I$3$m$+<+A3$K;W$$$D$/J}K!$J$s$G$7$g$&$M!#(BPerl$B0J30$N%W%m(B
$B%0%i%`8 @ 8l$G$b;H$($kJ}K!$@$7!#0lJ}%$%s%G%C%/%9$r%=!<%H$9$kJ}K!$O!"(B
$B:G8e$KG[Ns%9%i%$%9$r;H$C$F$$$k$H$3$m$,(BPerl$B$K0MB8$7$F$$$F!"$`$7$m(B
$B$3$C$A$NJ}$,%H%j%C%-!<$G$9!#(B
$B$"$H!"2NBe$5$s$NNc$G$O:G=i$K=i4|2=$9$k$H$-$K(Bmap$B$r;H$C$F$$$^$9$,!"(B
$B$3$l$O(Blength$B$,(B1$B$D$N%9%+%iCM$rI,$:JV$9$3$H$,$o$+$C$F$$$k$+$i$G$-(B
$B$k$s$G$"$C$F!"IaDL$O(Bperlfaq4$B$d(Bperldoc -f sort$B$N$h$&$K(Bfor$BJ8$G$d$i(B
$B$J$$$H$^$:$$$G$9!#(B
wrong:
@keys1 = map { getkey1($_) } @unsorted;
@keys2 = map { getkey2($_) } @unsorted;
right:
for (@unsorted) {
push(@keys1, getkey1($_));
push(@keys2, getkey2($_));
}
$BM}M3$O$_$J$5$s$*$o$+$j$G$9$M!#(B
$B:#DE$5$s(B> $B$9$_$^$;$s!"(BJAPH $B$C$F2?$G$9$+!#(B
Just Another Perl Hacker$B$NN,$G$9!#(BRandal L. Schwartz$B$,%K%e!<%:$K(B
$B%]%9%H$9$k$H$-!"%7%0%M%A%c$K!V(B"Just Another Perl Hacker"$B$r=PNO$9(B
$B$kC;$$(BPerl$B%W%m%0%i%`!W$rKhEY=q$$$F$$$?$b$N$G$9!#MM!9$J%H%j%C%/$r(B
$B6n;H$7$F$$$F!"$J$<$3$l$G$=$&$$$&F0:n$K$J$k$+9M$($k$HHs>o$K(BPerl$B$N(B
$BJY6/$K$J$k$H$$$&(B($B$=$7$F(Bobfuscated$B$J%3!<%I=q$-$K0i$D$H$$$&(B :))$B$b(B
$B$N$G$9!#(BRandal$B$O%]%9%H$9$k5-;v$NFbMF$K9g$o$;$F$=$NETEY%H%j%C%/$r(B
$B9M$($F$$$?(B($B%9%H%C%/$rMQ0U$7$F$$$J$+$C$?(B)$B$=$&$G$9!#$5$9$,$G$9$M!#(B
http://www.cpan.org/misc/japh
$B$&!A$s!":#$N:#$^$G(Bwww.cpan.org$B$H$$$&$N$rK:$l$F$$$?!D!D!#$$$D$+$i(B
$B$"$k$s$@$m$&!#(B
------------------------------- Vulture LRM20 .$B""(B||$B""(B. LRM20
$BA0ED(B $B70(B maeda @ src.ricoh.co.jp 75t 175km/h Md+ o'$B""(B||$B""(B`o Md+
($B3t(B)$B%j%3!<(B $B%=%U%H%&%'%"8&5f=j(B HeatSink 18 LG Sm+ .=X~~X=. Sm+ LG
------------------------------- Armor 2195 _|_ _|_
Tokyo-pm メーリングリストの案内