http://www.perlmonks.org?node_id=1038142

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

Replies are listed 'Best First'.
Re: special character substitution
by choroba (Cardinal) 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 (Archbishop) 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'