Re: substituting 1 escaped character for another
by pryrt (Abbot) on Jul 26, 2018 at 16:59 UTC
|
__LINUX__
sh-3.00$ perl -le 'print $x = "healthy(b"; $x =~ s/\(/\</; print $x'
healthy(b
healthy<b
sh-3.00$ perl -v
This is perl, v5.8.5 built for i386-linux-thread-multi
...
__WINDOWS__
C:\>perl -le "print $x = 'healthy(b'; $x =~ s/\(/\</; print $x"
healthy(b
healthy<b
C:\>perl -v
This is perl 5, version 26, subversion 2 (v5.26.2) built for MSWin32-x
+64-multi-thread
...
| [reply] [d/l] |
|
Also note that the backslash in the replacement part is useless and could be even misleading as someone might think that \< has a special meaning.
s/\(/</
If there are more parentheses to replace, use the /g modifier:
s/\(/</g
Also, in case of single character replacements, you can use transliteration:
tr/(/</
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
| [reply] [d/l] [select] |
Re: substituting 1 escaped character for another
by herveus (Prior) on Jul 26, 2018 at 17:02 UTC
|
Howdy!
I executed those two lines, and it worked fine for me.
Can you tell us more about your environment? Because that code should be fine.
| [reply] |
|
Thanks for responding you all. My server is running Apache/2.0.64 (Win32) mod_perl/2.0.3 and Perl/v5.8.3. My server is an off the shelf PC running the latest version of Windows 10. The application executes in the WWW environment. I test on the latest versions of IE, Edge, FF, O, and Chrome.
| [reply] |
|
| [reply] |
|
I'm guessing a bit here, but when you say "The application executes in the WWW environment", I'm guessing that you are trying to modify an HTML page? Show us a segment of the HTML page and your code to decode and encode text -> HTML. Your regex will work fine on regular text, but I suspect that is not what you actually have.
In recent memory, I did a quickie kludge to handle the ampersand character in one "get it done right now" LWP application, $clubName =~ s/&/&/g; & is what HTML needs to display the ASCII & character. I suspect something similar is going on. We need more info...
| [reply] [d/l] [select] |
|
|
|
|
Re: substituting 1 escaped character for another
by kcott (Archbishop) on Jul 27, 2018 at 11:24 UTC
|
G'day craigt,
"I have not been able to substitute or transform, split, or substr."
You could use any of those methods.
I'm assuming by "transform" you mean transliteration (i.e. y/// aka tr///).
I acknowledge that some of these solutions have already been posted.
- substitution
-
$ perl -E 'my $x = "A(B"; $x =~ s/\(/</; say $x'
A<B
- transliteration
-
$ perl -E 'my $x = "A(B"; $x =~ y/(/</; say $x'
A<B
- split
-
$ perl -E 'my $x = "A(B"; $x = join "<", split /\(/, $x; say $x'
A<B
- substr
-
$ perl -E 'my $x = "A(B"; substr $x, index($x, "("), 1, "<"; say $x'
A<B
Now use Benchmark to compare the different methods.
Please post the results as I (and probably others) would be interested.
| [reply] [d/l] [select] |
Re: substituting 1 escaped character for another
by theravadamonk (Scribe) on Jul 30, 2018 at 05:13 UTC
|
print "Content-Type: text/html; charset=utf-8\n\n";
Can u change it for a moment to below line and see...
print "Content-Type: text/text\n\n";
Now run via web browser
| [reply] [d/l] [select] |
|
Thank everyone for responding. I had a Windows 10 update overnight the night after I made this post and this problem was no longer. I don't know. Thanks again.
| [reply] |