in reply to Re: If I Want Backslashes, I'll Ask For Backslashes
in thread If I Want Backslashes, I'll Ask For Backslashes

If that's the case, I can understand \', but what's the rationale behind \\? Seems to me to be a little unusual, which is the source of this question.
  • Comment on Re^2: If I Want Backslashes, I'll Ask For Backslashes

Replies are listed 'Best First'.
Re^3: If I Want Backslashes, I'll Ask For Backslashes
by CheeseLord (Deacon) on Aug 11, 2001 at 00:40 UTC

    Well, you've gotta have \\... how else do you write the escape character? Without \\, '\' is a syntax error, so you need some way of getting the escape character into the string - and doubling it seems to be common convention. However, in the single-quoted here doc, it becomes unnecessary as the only thing that could possibly need escaping is the ending string - and, um... well, if you need to escape that, then I suggest picking a better end string. :-)

    Update: Well, John's right - but the need does exist to include the quoting character inside the string, and if the escape character is at the end of the string, there needs to be some way to do that without causing the interpreter to freak out.

    His Royal Cheeziness

Re: Re^2: If I Want Backslashes, I'll Ask For Backslashes
by John M. Dlugosz (Monsignor) on Aug 11, 2001 at 00:50 UTC
    Not quite what Cheezy said... I understand it this way. If \ is normally ignored, and only\'is special (meaning '), how do you really write \'? That's the only time you must write \\ when you meant \. But, since it exists, you need to use it also to write \\ (as \\\\) etc. Other than that, you don't need to write \ as \\ in a single-quote, but you could.

    —John

      Here's my, possibly skewed, reasoning as to how it should work, at least in one sense:
      $_ = '\\something'; # \\something $_ = 'It\'s a tragedy'; # It's a tragedy $_ = '\\''; # \'
      Of course, the last example would probably strike many a C programmer as being far too bizarre to comprehend.

      This is why I expected the q() operator to behave differently. As it was pointed out, the only reason for \\ is because of the requirement for \', which would imply that if \' were no longer an issue, \\ would cease to be relevant as well.

      Here's what I would expect, and yet this is not the case:
      $_ = q[\\something]; # \\something $_ = q[It's a tragedy]; # It's a tragedy $_ = q[\']; # \'
      Update:
      The last "should" example is parsed as such:
      ',\,\','
      That is to say, that this is really a single quote, followed by a single backslash, followed by the token \', followed by a single quote.
        I don't understand your last "should" example. But I agree that it makes sense that the reason you need to escape would follow the closing delimiter. So in qq/blab/ you would need to escape out any contained / character, but not any ' character.