| String-Gsub documentation | view source | Contained in the String-Gsub distribution. |
String::Gsub::Functions - core functions of String::Gsub
use String::Gsub::Functions qw(gsub);
print gsub("abcabc", qr/(b)/,sub{uc$1}); # ==> "aBcaBc"
gsubx(my $str = "abcabc", qr/(b)/, sub{uc $1});
print $str; # ==> "aBcaBc";
This module has folloing functions:
gsub ($str, $regexp, $replacement) gsubx($str, $regexp, $replacement) subs ($str, $regexp, $replacement) subsx($str, $regexp, $replacement)
$regexp is regular expression (qr//).
And $replacement is code reference, which is invoked at replacement.
In $replacement subroutine, match variables ($1, $2, ...)
are avaiable like replacement part of s/PATTERN/REPLACEMENT/.
Both $regexp and $replacement can be string,
but there are difference from usual part.
String passed on $regexp is not treated as regular expression
, just string. special chars will be escaped.
String passwd on $replacement will be replaced some substrings
with match strings and used as replacement string.
\&, \` and \' are also did.
This module can export gsub, gsubx, subs, subsx.
process global substitute, and return new string.
like gsub, but replace self string and return itself.
process one substitute, and return new string.
like subs, but replace self string and return itself.
| String-Gsub documentation | view source | Contained in the String-Gsub distribution. |