Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Backslash sequence inTcl

Posted by skumar003 (skumar003), 6 February 2003
What is the use of backslash sequence in Tcl?

Eg:

set  path  [pwd]
set  tcc \\
set  path &path$tcc

where is my path finally set to? Is this for use in windows to fetch a file?

Cheers,


Posted by admin (Graham Ellis), 7 February 2003
The \ character in Tcl gives an alternative meaning to the next chartacter.    

If you write backslash followed by a special character, then the following character is not treated as special - you're telling Tcl that you REALLY want that second character as just a normal character, even if it would normally do something special.

If you write a backslash followed by a letter or digit, then the following character has a special significance not normally associated with it.

Examples
  \$    I want a $ character
  \\     I really want a \ character
  \n    I want a newline character

Your example code

set  path  [pwd]
    set path to contain the result of running the pwd command
set  tcc \\
    set tcc to contain a single \ character
set  path &path$tcc
    overwrite path with the string "&path" followed by the
    contents of the variable tcc,  giving  &path\

A further complication of \  ... It ALSO has special meanings in regular expressions, and if you need to have it in a regular expression you have to get it through the Tcl interpretter.  Thus it's quite common to see a regular expression command than includes something like
      \\\*
which means "I REALLY want to look for a *".   The Tcl interpretter reduces the string above to
      \*
which is the "I really want a *" to the regular expression handler.




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho