Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

special character substitution

by bill b (Initiate)
on Jun 10, 2013 at 19:41 UTC ( #1038142=perlquestion: print w/ replies, xml ) Need Help??
bill b has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm polishing man page output from pandoc (google it). I need to clean up cruft that occurs around the man page bullet macros and replace it with \(bu (bullet macro syntax). Here's what I have:

s/T\}\@T.*T\}\@T\{/\(bu/sm;

The matching works perfectly, but no matter how much I play with the substitution string, I always get (bu without the initial backslash. I've tried /\\(bu/, /\\\(bu/, /Q and /E, but nothing works. I always get (bu in the output.

TIA, Bill

Comment on special character substitution
Download Code
Re: special character substitution
by choroba (Abbot) on Jun 10, 2013 at 19:57 UTC
    Works for me:
    $_ = "T}\@T...T}\@T{"; s/T\}\@T.*T\}\@T\{/\\(bu/sm; print;

    Output:

    \(bu
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thanks. I'm an idiot--I was inadvertently erasing the \ in another part of postprocessing. Sigh. thanks again, bill
Re: special character substitution
by AnomalousMonk (Abbot) on Jun 10, 2013 at 22:08 UTC

    Also, using  ' (single-quote) as a delimiter for either or both of the substitution pattern or replacement string of a  s/// will force the use of single-quotish (non-)interpolation and escapology.

    >perl -wMstrict -le "$_ = 'T}@T...T}@T{'; s'T}@T.*T}@T{'\(bu'sm; print qq{'$_'}; " '\(bu'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1038142]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-12-22 06:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (111 votes), past polls