Re: How to treat puts <value> as pure text - not a command



steve wrote:
Hi Uwe,
This is the part doing the reading and writing...
----------------------------------------------------------------------------------
while { [gets $infile in_line] >=0 } {
set open_comment [lsearch -exact $in_line "/*"]
set close_comment [lsearch -exact $in_line "*/"]
...
> switch -glob -- $title {
default
{
puts $outfile "$in_line"
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------

I've found that if the $in_line contains an unmatched '{' the script
errors with 'unmatched open brace in list'

The line being processed falls into the 'default' switch


I find it very difficult to believe your code makes it that far. It should choke on the lines where you try to do an lsearch command. Read the man page on lsearch and you'll see it requires a list on input. If your data has unbalanced braces as you say it does, they are decidedly not lists.

The cardinal rule is "never use list commands on strings", which is exactly what you are doing.

Use string first or regexp or something, or use split to convert the string to a list before using list commands.


--
Bryan Oakley
http://www.tclscripting.com
.



Relevant Pages

  • Re: Extracting patterned filenames from [glob] without a loop - possible?
    ... If it is indeed a string, it's ok to use regsub here. ... lists, and with the transformations you are doing above it seems ... on unix. ... This is another case of using list commands on a string. ...
    (comp.lang.tcl)
  • Re: How to support string contains unpaired " and {
    ... string elements using lindex. ... those strings need to be lists from the beginning. ... set var "123{\"456" ... Your only other alternative is to change those list commands to be ...
    (comp.lang.tcl)
  • Re: special characters treated as text (not trivial I think)
    ... > to a function that, for example, saves the string to a file, it'll ... you're taking a string and using list commands ... ahead of time to be well formed tcl lists. ...
    (comp.lang.tcl)
  • Re: Perl vs Python vs Ruby.... vs Tcl?
    ... which joined the string. ... It is certainly possible to read a string in from a file and use list commands on it without first explicitly converting it to a list. ... Tcl has always had the ability to automatically convert strings to lists, provided the strings are in a suitable format. ...
    (comp.lang.tcl)
  • Re: Tree as nested list
    ... nested lists". ... and and z using the list commands. ... I know the string representations ... not work as-is for "linear" trees. ...
    (comp.lang.tcl)