Perl 反轉函式



說明

該函式在列表上下文中反轉 LIST 中的元素。在標量上下文中,返回 LIST 值的連線字串,其中所有位元組順序相反。

語法

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

reverse LIST

返回值

此函式在標量上下文中返回字串,在列表上下文中返回列表。

示例

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

#!/usr/bin/perl -w

@array = (2,3,4,5,6,7);
print "Reversed Value is ", reverse(@array), "\n";
$string = "Hello World";
print "Reversed Value is ", scalar reverse("$string"), "\n";

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

Reversed Value is 765432
Reversed Value is dlroW olleH
perl_function_references.htm
廣告
© . All rights reserved.