Perl sort 函式



說明

此函式根據子程式 SUBNAME 或由 BLOCK 指定的匿名子程式對 LIST 進行排序。如果沒有指定 SUBNAME 或 BLOCK,則按正常的字母順序進行排序。

如果指定了 BLOCK 或 SUBNAME,則子程式應根據陣列元素的排序方式返回小於零、大於零或等於零的整數

語法

以下是此函式的簡單語法 -

sort SUBNAME LIST

sort BLOCK LIST

sort LIST

返回值

此函式返回已排序的列表。

示例

以下是顯示其基本用法示例的程式碼 -

#!/usr/bin/perl -w

@array = ("z", "w", "r", "i", "b", "a");
print("sort() ", sort(@array), "\n");

執行上述程式碼後,將產生以下結果 -

sort() abirwz
perl_function_references.htm
廣告
© . All rights reserved.