# sort 預設使用字母順序升冪排序
@articles = sort @files;

# 同上,使用字母順序升冪排序
@articles = sort {$a cmp $b} @files;

# 同上,使用字母順序降冪排序
@articles = sort {$b cmp $a} @files;
@articles = reverse sort @files;

# 使用數字順序升冪排序
@articles = sort {$a <=> $b} @files;

# 使用數字順序降冪排序
@articles = sort {$b <=> $a} @files;

# 不分大小寫字母順序排序
@articles = sort {uc($a) cmp uc($b)} @files;
@articles = sort {lc($a) cmp lc($b)} @files;

# 使用字串長度順序排序
@articles = sort {lenth($a) <=> length($b)} @files;

# 使用字串長度與字母順序排序
@articles = sort {lenth($a) <=> length($b) || $a cmp $b} @files;

# %age雜湊值降冪排序
@eldest = sort { $age{$b} <=> $age{$a} } keys %age;
arrow
arrow
    全站熱搜

    搗蛋鬼 發表在 痞客邦 留言(0) 人氣()