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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho