師匠の散歩

きままにPerlでも

check sort

sort の勉強/ checkSort.cgi

文字の配列

@key1 = ("a","bcd","ab","abc","b","c");
a/bcd/ab/abc/b/c
@key2 = sort { $a cmp $b } @key1;
a/ab/abc/b/bcd/c
@key2 = sort @key1;
a/ab/abc/b/bcd/c
@key2= sort { $b cmp $a } @key1;
c/bcd/b/abc/ab/a
@key2= reverse sort @key1;
c/bcd/b/abc/ab/a
@key2= sort { $a <=> $b } @key1;
a/bcd/ab/abc/b/c

数字の配列

@key1 = ("1","3","100","67","03","x");
1/3/100/67/03/x
@key2 = sort @key1;
03/1/100/3/67/x
@key2= sort { $a <=> $b } @key1;
x/1/3/03/67/100
@key2= reverse sort @key1;
x/67/3/100/1/03
@key2= sort { $b <=> $a } @key1;
100/67/3/03/1/x
@key2 = sort { $a cmp $b } @key1;
03/1/100/3/67/x

checkSort.cgi // Topに戻る // indexに戻る
Copyright(C) 2009-2021 Grandmaster Last up : 2020/09/18