in reply to Escaping the escaping escape character

Try:
$scriptSource =~ s/\\/\\\\/g;
Jeremy

Replies are listed 'Best First'.
Re: Escaping the escaping escape character
by cLive ;-) (Prior) on Jun 25, 2001 at 01:36 UTC

    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