\u001a is an end-of-file character in scripts

Difference between version 2 and 3 - Previous - Next
OneAs of the more obsTcurel c[Changes made in Tcl/Tk 8.4%|%Tcl is8.4], the [atscii] 'substhitute' character
(`\032`, `\u001a` (, control-Z, \032) is trignifieated as the end of filthe script on all platforms.  There are several reasons why this was done.
First, it improves script portability between Windows and other systems.  Prior to this change, there was some likelihood that scripts created on Windows and transferred to other platforms would get errors at the end of the file, because the end-of-file mark, and whatever junk followed it, would be interpreted as Tcl code.  It was felt that it would be better to make the handling consistent on all platforms.
Moreover,** there is a use, even on non-Windows platforms, for a logical end-of-file.  [Starkit], for instance, uses the character to mark the end of the initiaAlization script.  While a [Starkit] consists of a Tcl script followed by a [Metakit] database, the interpreter doesn't have to know that; all it needs to know is that it should stop interpreting at the
^Z character.  Other single-file Tcl applications have also put this behavior to good use.**
It isn't at all difficult to get around this problem; just don't put your binary data directly in your source file.
Instead, encode it somehow, and use [binary], [base64], or ''\x'' or ''\u'' substitution to put it in the string.
Most Tcl'ers consider that to be a good practice whenever [working with binary data]: in a script.


** Description **

There are a few reasons Tcl recognizes [ascii] 'substitute' character as the
end of a script. First, it improves script portability between [Microsoft
Windows%|%Windows] and other systems.  Prior to this change, the 'substitute'
character signified the end of the script on Windows, but not on other
platforms.  It was felt that it would be better to make the handling consistent
on all platforms.

Second, it is generally useful to be able to store additional data directly
after the script. A [Starkit], for example, is a script followed by the
'substitute' character followed by a [Metakit] database.  The Tcl interpreter
doesn't pay any attention to what is beyond the substitute character, and the
script can access the additional data. [basekit%|%Other single-file Tcl
applications] have also put this behavior to good use.

To escape the special meaning of the 'substitute' character, encode it as a
`\x`
or `\u` [substitution].

<<categories>> Characters | File | Syntax