Perl 函式



描述

這不是函式。這是正則表示式替換運算子。基於 PATTERN 中指定正則表示式,資料將由 REPLACE 替換。如 m//,分隔符由 s 後的第一個字元定義。

語法

s/PATTERN/REPLACE/

示例

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

#!/usr/bin/perl -w

$string = "This is Test";
# this will replace Test with Best.
$string =~ s/Test/Best/;

print "$string\n";

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

This is Best
perl_function_references.htm
廣告
© . All rights reserved.