Re: Is it possible to have special characters in list



On Sep 1, 1:49 pm, Terminator <manidevara...@xxxxxxxxx> wrote:
Folks,
I am trying to loop through the following o/p which has special
characters in it like { & [. But when i run, it returns "unmatched
braces". Can you suggest how to handle this case.

Data:
0xf3a1a44c: 0x7BE6CAE2 0xBEA05B1A 0xD5D37E2B 0xA3AD6835 {.....[...~
+..h5
0xf3a1a45c: 0x81BA9D75 0xAAEFC8F5 0x72DCDAA4
0x92C3441E ...u....r.....D.

My code:
foreach elem $Data {
.....

}


It appears that $Data isn't a proper list. What is the delimiting
character in your $Data? If all the elements are delimited by a single
space then you can do:

foreach elem [split $Data " "] {
do_something $elem
}

If, as I suspect, $Data is whitespace delimited then you have to coax
it into a form that is more easily splitable:

regsub -all -- {\s+} $Data " " Data
foreach elem [split $Data " "] {
do_something $elem
}

In tcl, a list is not simply a string of whitespace separated
words(1). A list is a string of whitespace separated words(1) where
braces are properly quoted or escaped. That is why you should not
trust external data to be proper lists(2). You should always parse the
data first.

Notes:
(1) "Word" here is as recognised by the tcl command parser. For
example {this is one word} is a single word since it's grouped by {}.

(2) I actually often treat external data directly as lists. In which
case I define the expected data format to be a proper tcl list and so
any errors encountered is not considered a "bug" in my program but
user/configuration error ;-)


.



Relevant Pages

  • Re: [ltp] News Flash
    ... Even if some Debian ... and DRM this really isn't the proper group. ... or mailing lists more on topic. ... it there I search Debian.org with Google using site search, ...
    (Debian-User)
  • Re: [ltp] News Flash
    ... and DRM this really isn't the proper group. ... or mailing lists more on topic. ... then I search Google groups if need be. ... it there I search Debian.org with Google using site search, ...
    (Debian-User)
  • Novice List to Vector question
    ... I have some code I'm changing to use vectors instead of lists. ... (defgeneric elem (location collection) ... (nth location collection)) ...
    (comp.lang.lisp)
  • Re: NIL is not of type CONS
    ... The key phrase here is "upon encountering". ... This would allow mapcar and others to only test ... proper-conses doesn't preclude proper lists being constructed with ...
    (comp.lang.lisp)
  • Re: Question for the MVPs
    ... one that I'm particulary proud of is a combo box that lists the proper names of resorts (e.g. Disney's Grand Floridian Resort) into which you can type a short description which does not appear in the list and have the proper name selected. ... It isn't that you need to write an application to receive an MVP award, rather it is recognition of your contribution to the support of some Microsoft product. ...
    (microsoft.public.access.modulesdaovba)