Perl 的 `y` 函式



描述

此函式與 `tr///` 運算子相同;將 `SEARCHLIST` 中的所有字元轉換成 `REPLACEMENTLIST` 中對應的字元。它執行逐個字元轉換

語法

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

y/SEARCHLIST/REPLACEMENTLIST/

返回值

此函式返回修改的字元數。

示例

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

#!/usr/bin/perl -w

$string = 'the cat sat on the mat.';

# This will generate a upper case string
$string =~ y/a-z/A-Z/;

print "$string\n";

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

THE CAT SAT ON THE MAT.
perl_function_references.htm
廣告
© . All rights reserved.