user2742564
user2742564

Reputation: 119

Confusion in TCL substitution

I am confused with the following statements .

  1. % set a \\\\\w
    \\w
    
  2. % set a \\\\w
    \\w
    
  3. % set a \\w
    \w
    

In the First statement I am having 5 (backslashes) and it produced 2 (backslashes) as output.

In the second statement I am having 4 (backslashes) and it produced 2 (backslashes) as output.

In the Third statement I am having 2 (backslashes) and it produced 1 (backslashes) as output.

Up to my knowledge \\ is equal to \ after substitution .

As it is \\\\\ it should return single \ na.

Can Anyone Please Explain me how the substitution occures.

Upvotes: 0

Views: 55

Answers (1)

Johannes Kuhn
Johannes Kuhn

Reputation: 15173

Well, it is simple:

  • There are some special subsitutions, including \\ will be substituted into \, so \\\\ will be replaced with \\ (not a single \). For a list of all special substitutions, see the manual.
  • On other escape sequences (like \w) the backslash will be removed. From the manual:

    In all cases but those described below the backslash is dropped and the following character is treated as an ordinary character and included in the word.

Upvotes: 2

Related Questions