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/.
$regexp
qr//
$replacement
$1
$2
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.
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
To install String::Gsub, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Gsub
CPAN shell
perl -MCPAN -e shell install String::Gsub
For more information on module installation, please visit the detailed CPAN module installation guide.