Char-Replace
view release on metacpan or search on metacpan
lib/Char/Replace.pm view on Meta::CPAN
=item an empty string â deletes the character from the output
=item an integer (IV) â replaces the character with C<chr(value)> (0â255)
=item undef â keeps the original character unchanged
=item a code ref â called with the character as argument; return value is the replacement
(return undef to keep original, empty string to delete)
B<Note:> Code ref callbacks are significantly slower than static replacements due to
function call overhead. Avoid heavy computation inside callbacks. Callbacks receive
a single-character string argument; for tainted input, the output string inherits the
taint flag from the input (not from the callback return value).
=back
view L</SYNOPSIS> or example just after.
Setting a map entry to an empty string deletes the character from the output:
$map->[ ord('x') ] = q[]; # delete 'x'
lib/Char/Replace.pm view on Meta::CPAN
=item a single-character string (PV of length 1)
=item an integer (IV) in range 0â255
=item undef â keeps the original character unchanged
=back
Multi-character strings, empty strings (deletion), and code refs will cause a croak.
Use C<replace()> when you need expansion, deletion, or dynamic callbacks.
my $map = Char::Replace::identity_map();
$map->[ ord('a') ] = 'A';
my $str = "abcabc";
my $n = Char::Replace::replace_inplace( $str, $map );
# $str is now "AbcAbc", $n is 2
UTF-8 safety applies: multi-byte sequences are skipped, only ASCII bytes
are eligible for replacement.
( run in 2.702 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )