You're not performing any substitution, you're just matching, as qr just returns a regex object
#!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; my $infile = '...'; my $outfile = '...'; my $find = VerifyHex( '\xe9' ); my $replace = VerifyHex( '\x65' ); my $IF = path( $infile )->openr_raw; my $OF = path( $outfile )->openw_raw; while( my $str = <$IF> ){ $str =~ s{$find}{$replace}g; print $OF $str; } close $IF; close $OF; sub VerifyHex { my( $str ) = @_; if( $str =~ m/(\\[a-zA-Z0-9][a-zA-Z0-9])/ ){ return "$1"; } die "evil input $str"; }
Yes you could use https://metacpan.org/pod/Path::Tiny#edit_lines-edit_lines_utf8-edit_lines_raw but I didn't want to change code too much
In reply to Re: Hex-matching Regex pattern in scalar ( substitution
by Anonymous Monk
in thread Hex-matching Regex pattern in scalar
by CliffG
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |