
Regexp::Subst::NoRegex - emulate s/// using s/\Q// or substr

use Regexp::Subst::NoRegex qw/rnr_substr rnr_sop/;
my $text = "ajim jam jom ejeme";
my $copy = $text;
$copy =~ s/\bj(.)(.)/$2 $1/g;
my $copy1 = rnr_substr ($text, '\bj(.)(.)', '$2 $1');
my $copy2 = rnr_sop ($text, '\bj(.)(.)', '$2 $1');
if ($copy eq $copy2 && $copy eq $copy1) {
print "OK\n";
}

Given $text, a regex $left and a right hand side $right, perform the substitution $text =~ s/$left/$right/g; without using regular expressions for the substitution operation.
The module contains two different algorithms. One, rnr_substr, uses substr to perform the substitutions, and the other, rnr_sop, uses multiple non-regex substitutions of the form $text =~ /\Q$x/$y/ to emulate Perl's regex substitution while actually switching it off with the \Q.
Exports rnr_substr (substr version) and rnr_sop (s/\Q// version) on request.
Set
$Regexp::Subst::NoRegex::verbose = 1;
to see what the module is doing.
Regular expression substitution without using any regular expressions (rnr stands for regex no regex) - emulate
$text =~ s/$left/$right/g;
with a series of substitutions which use Perl's built in function substr
substr ($text, $position, $length) = $y;
The text you want to substitute
Any LHS expression, including regular expressions.
Any RHS expression, including things like $1, $2, etc.
Regular expression substitution without using any regular expressions (rnr stands for regex no regex) - emulate
$text =~ s/$left/$right/g;
with the subsitution operator (s///) with regexes switched off.
$text =~ s/\Q$x/$y/g;
This is a hash reference containing
callback routine for global substitutions
Takes arguments ($data, $left, $right) where $left should be globally substituted for $right, and $data is the data from $subsop{data}.
callback routine for sequential substitutions
Takes arguments ($data, $left, $right, $orig, $gb_list);
where $gb_list is a list of good or bad substitutions in the form ('good', 'bad', 'bad', 'good', 'good'), and $left should be substituted with either $right or $orig depending on whether $gb_list says "good" or "bad". $data is $subsop{data}.
data to send to the callback routines.

Ben Bullock, <benkasminbullock@gmail.com<gt>

Copyright (C) 2008 by Ben Kasmin Bullock.
This module is distributed under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.