珀尔 |替换运算符
Perl 中的替换运算符或“s”运算符用于将字符串的文本替换为用户指定的某种模式。
Syntax: s/text/pattern
Returns: 0 on failure and number of substitutions on success
示例 1:
#!/usr/bin/perl -w
# String in which text
# is to be replaced
$string = "GeeksforGeeks";
# Use of s operator to replace
# text with pattern
$string =~ s/for/to/;
# Printing the updated string
print "$string\n";
输出:
GeekstoGeeks
示例 2:
#!/usr/bin/perl -w
# String in which text
# is to be replaced
$string = "Hello all!!! Welcome here";
# Use of s operator to replace
# text with pattern
$string =~ s/here/to Geeks/;
# Printing the updated string
print "$string\n";
输出:
Hello all!!! Welcome to Geeks