📜  珀尔 |替换运算符

📅  最后修改于: 2022-05-13 01:55:04.057000             🧑  作者: Mango

珀尔 |替换运算符

Perl 中的替换运算符或“s”运算符用于将字符串的文本替换为用户指定的某种模式。

示例 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