Perl 的 join 函式



描述

此函式使用 EXPR 將 LIST 元素合併到一個字串中,並用 EXPR 值分隔各個元素。實際上,它與 split 相反。

請注意,EXPR 僅插入到 LIST 中元素對之間;它不會放在字串中第一個元素之前或最後一個元素之後。要連線字串而不使用分隔符,請提供一個空字串,而不是 undef。

語法

以下為該函式的簡單語法 −

join EXPR, LIST

返回值

此函式返回連線的字串。

示例

以下示例程式碼顯示了其基本用法 −

#!/usr/bin/perl

$string = join( "-", "one", "two", "three" );
print"Joined String is $string\n";

$string = join( "", "one", "two", "three" );
print"Joined String is $string\n";

當執行上面的程式碼時,將產生以下結果 −

Joined String is one-two-three
Joined String is onetwothree
perl_function_references.htm
廣告
© . All rights reserved.