CliffG has asked for the wisdom of the Perl Monks concerning the following question:
I know the substitution '$str =~ s/\xe9/\x65/g;' works just fine but parameterising it is the problem. Straightforward for char strings but seemingly less so for hex ones ... Can someone please advise?my $pre = '\xe9'; my $post = '\x65'; my $re = qr/s\/$pre\/$post\/g/; my $path = 'C:\Scripts\Working2'; my $fileSep = "\\"; my $file = 'Users_0.xml'; my $tempFile = 'C:\Scripts\Working2\Users2.xml'; if (!open(IF, "<$path$fileSep$file")) { die("Could not open file $path$fileSep$file $!"); } if (!open(OF, ">$tempFile")) { die("Could not open file $tempFile $!"); } while($str = <IF>) { $str =~ $re; print OF $str; } close IF; close OF;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hex-matching Regex pattern in scalar
by hippo (Archbishop) on May 20, 2016 at 11:02 UTC | |
|
Re: Hex-matching Regex pattern in scalar
by Corion (Patriarch) on May 20, 2016 at 11:04 UTC | |
by CliffG (Novice) on May 20, 2016 at 12:17 UTC | |
by Corion (Patriarch) on May 20, 2016 at 12:25 UTC | |
by hippo (Archbishop) on May 20, 2016 at 12:55 UTC | |
by CliffG (Novice) on May 20, 2016 at 13:34 UTC | |
|
Re: Hex-matching Regex pattern in scalar ( substitution
by Anonymous Monk on May 20, 2016 at 09:51 UTC | |
by CliffG (Novice) on May 20, 2016 at 11:13 UTC |