Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am on Win32, AS 5.8.7.
I am ran into a character substitution problem, any enlightment would be great. I built a pure perl Pdf module and was testing my tables with some ascii art. I have to escape every '\' with '\\' in the string I embed in the Pdf. This code does work, but only if the '\' is not followed by another '\':
$txt = ' \*/ '; $txt =~s/\\/\\\\/g; # what I expected ' \\*/ '; print $txt;
but, it does not work when there this 2 or more
$txt = ' __\\U//__ '; $txt =~s/\\/\\\\/g; print $txt; #prints __\\U//__
I needed it to do this '__\\\\U//__'
Can anyone show me how to do this?
Thanks,
JamesNC
This is kindof solved, thanks to everyone who responded.
Update: I posted a follow-up. I would still like some more info on why ikegami's suggestion of streaming the data makes a difference.
Closing note:
This is a "special helpful programming feature" of perl that backslashes are interpreted as backslashes inside of single quotes except in the case where a backslash is followed by another backslash, in which case the pair escape each other. It is documented in perlop as was pointed out to me by ambrus. All this because I started messing with ascii art.

In reply to Escaping multiple escape chars by JamesNC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found