Parsing for quote operators

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am trying to read the perlop documentation page.

I see double-quoted strings are processed in two phases:
  1. delimiter scan phase, which also skips and replaces backslash escapes:
     - \" is replaced with "
     - \ is replaced with \
  2. interpolation phase, which also processes other backslash escapes, so that:
     - \t is replaced with the actual tab character

It looks to me that the literals "\t" and "\t" should after phase 1 return exactly the same string, and after phase 2 should turn into the same one-character string (with the character code for a tab).

However if I use these literals in a perl script I do not get the same results.

Is it something that I do not understand right ?
May I suggest that the perldoc page be updated to make things clear ?

Thank you,
Adrian Constantin

Re: Parsing for quote operators

Quoted text here. Click to load it

Since this would imply one couldn't put a backslash in front of a
character which could be part of \-escape, it should have occurred to
you that this couldn't possibly be correct. The 5.14.2 perlop states that

    During the search for the end, backslashes that escape
    delimiters are removed (exactly speaking, they are not copied to
    the safe location).

It doesn't talk about other backslashes. Since the first \ in the string
"\t" doesn't escape a delimiter, it won't be removed and the result
after \-escape processing will be "\t" and not a string containing a
single HTAB character.

Re: Parsing for quote operators

The perlop page says:

   "backslashes that escape delimiters or other backslashes are removed"

so \ is replaced with \ in phase 1, and then escapes are processed in phase 2.
It follows that "\t" means "\t".

Re: Parsing for quote operators

Quoted text here. Click to load it

That's what it was changed to say on 2012/03/23, cf

I couldn't find any background information on this.

Re: Parsing for quote operators

Well for single-quoted strings the message is right, '.\.' really equals '.\.'

But is incorrect for other strings (double-quoted), for which the perlop page is no longer accurate.

Re: Parsing for quote operators

On Wednesday, 26 August 2015 19:42:36 UTC+5:30, Adrian Constantin  wrote:

Quoted text here. Click to load it

For sure this is a bug in the documentation. The Step-1b is mistaken.
Only the backslashes preceding the delimiter are removed in this step,
all the rest are retained to be used in the next step of interpolation.

OTW, doing a "\" -> \ -> \ using the approach mentioned in doc as it exists.
Whereas, what we see is:  \  which can only happen if the backslashes preceding
a backslash are retained in step-1a, like as

     "\" -> \ -> \

Site Timeline