I posted this problem last week, but clearly I was not clear enough
I have a script that takes some user input
It then takes that string and writes (appends) some code
to the end of another perl script
Example:(pseudo-code)
#*** Script that takes user input ***
$userinput = getInput();
open THEOTHERSCRIPT ">>othersciprt";
print THEOTHERSCRIPT "print \"$userinput\"\; \n";
Now suppose the user inputs the following:
$dollars and %percents ARE "COOL!"
The script then appends the string to my OTHERSCRIPT
and the resulting script looks like such:
#*****OTHER SCRIPT******
print "$dollars and %percents ARE "COOL!"";
As you can see its not going to print what the user entered
Perl will try to do its magic on the $ and % and then the
quotes just confuse it.
So, my question is, is there an elegant way to put \ in front of
all the possible problem characters (ie $ % & " ' `, etc)
Or do I have to write a regex for each one??
I'd like to get this in one line of code ( ah hah! a challenge!)
Any takers???
Thanks!!!
Otijim
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.