Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Escaping the escaping escape character

by CiceroLove (Monk)
on Jun 24, 2001 at 22:44 UTC ( #91101=perlquestion: print w/replies, xml ) Need Help??

CiceroLove has asked for the wisdom of the Perl Monks concerning the following question:

I have started a website that allows AppleScripters to upload script libraries and the script source is displayed on the website for others to see.
Unfortunately the escape character is the same as in Perl. So whenever someone uses the \ then it gets stripped out when committed to the mySQL database. I have tried several solutions.

I tried:

$scriptSource =~ s/\\/\\\/g;

Which of course did not work. Then I tried:

$scriptSource =~ s/\\/&\#92/g;

Which of course also does not work. I have tried using \ any number of times. None of it works. I see that Perl Monks allows for escaped characters to display properly. How do I?

You can see what I mean by going to
http://applemods.citizenstrange.com/getMod.cgi?script_ID=16. The testMod's one line should read:
set theTestVar to "\""
Thanks for your help.

CiceroLove
Fates! We will know your pleasures: That we shall die, we know; 'Tis but the time, and drawing days out, that men stand upon. - Act III,I, Julius Caesar

Replies are listed 'Best First'.
Re: Escaping the escaping escape character
by enoch (Chaplain) on Jun 24, 2001 at 23:00 UTC
    Try:
    $scriptSource =~ s/\\/\\\\/g;
    Jeremy

      One thing you have to remember though is that if you're assigning \ to a string that it does interpolate in single quotes. Eg:

      # uninterpolated string my $string = '\\\\ double escape \single escape'; # print it print "$string\n"; # outputs - "\\ double escape \single escape" # do your replace $string =~ s/\\/\\\\/g; # print it again print "$string\n"; # output is '\\\\ double escape \\single escape'
      This can sometimes be confusing, because:
      $string = '\hello'; # and $string = '\\hello';
      are equivalent.

      Ow, my head hurts...

      cLive ;-)

        Actually in all this, I came to the realisation tht you can do:
        $scriptSource =~ s/\\/&\#92;/g;

        You'll notice that I hadn't used the semi-colon. That worked just fine and was great. Thanks for the help though I didn't realise how wierd all that could get.


        CiceroLove
        Fates! We will know your pleasures: That we shall die, we know; 'Tis but the time, and drawing days out, that men stand upon. - Act III,I, Julius Caesar

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2021-06-24 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (123 votes). Check out past polls.

    Notices?