Groups | Search | Server Info | Login | Register
Groups > comp.lang.tcl > #55584
| From | Choosechee <choosechee@pm.me> |
|---|---|
| Newsgroups | comp.lang.tcl |
| Subject | Re: How do I get an element of a list without it being substituted? |
| Date | 2026-03-18 16:31 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <10pf5k3$63l0$1@dont-email.me> (permalink) |
| References | <10pevmb$454s$2@dont-email.me> <3u1mrk9f4umn34q80nt08026dt3mvp1j5l@4ax.com> <10pf284$5p0r$1@dont-email.me> |
On 3/18/26 15:34, pmcc wrote:
> Helmut Giese wrote:
>> Choosechee <choosechee@pm.me> schrieb:
>>
>>> Let's say I have defined a list as follows:
>>> `set myList {"First\nElement" {Second Element}}`
>>> If I print this list:
>>> `chan puts $myList`
>>> I get:
>>> `"First\nElement" {Second Element}`
>>> However, if I were to iterate over the list and print the elements:
>>> `foreach {element} $myList {chan puts $element}`
>>> I get:
>>> ```
>>> First
>>> Element
>>> Second Element
>>> ```
>>> The elements have undergone substitution before being returned. In most
>>> cases, this is desirable, but in my case, I want them to be returned
>>> exactly as written, like:
>>> ```
>>> "First\nElement"
>>> {Second Element}
>>> ```
>>> How can I get an element of a list without it being substituted? I can't
>>> split the list by whitespace, because single elements that contain
>>> whitespace will also be split.
>> Hello,
>> by using 'llength'?
>> Like (all on one line)
>> for {set i 0} {$i < [llength $myList]} {incr i} {puts "$i: [lindex
>> $myList $i]"}
>> HTH
>> Helmut
>>
>
> Hello,
>
> Maybe building an explicit list is safer :
>
> set myList [ list {First\nElement} {Second Element} ]
>
> foreach element $myList { chan puts $element }
>
> > First\nElement
> > Second Element
>
> or if you collect data in different variables :
>
> set a {First\nElement}
> set b {Second Element}
>
> set myList [list $a $b]
> or
> set myList [list $a ]
> lappend myList $b
>
> foreach e $myList { chan puts $e }
>
> > First\nElement
> > Second Element
>
> note that this will fail :
> set myList $a
> foreach e $myList { chan puts $e }
>
> > First
> > Element
>
> Regards
> Pascal
>
In my actual use case, I'm reading the list from a file that someone
else could have made, so I can't do this.
Back to comp.lang.tcl | Previous | Next — Previous in thread | Next in thread | Find similar
How do I get an element of a list without it being substituted? Choosechee <choosechee@pm.me> - 2026-03-18 14:50 -0500
Re: How do I get an element of a list without it being substituted? Helmut Giese <hgiese@ratiosoft.com> - 2026-03-18 21:16 +0100
Re: How do I get an element of a list without it being substituted? pmcc <sysfl@free.fr> - 2026-03-18 21:34 +0100
Re: How do I get an element of a list without it being substituted? Choosechee <choosechee@pm.me> - 2026-03-18 16:31 -0500
Re: How do I get an element of a list without it being substituted? Choosechee <choosechee@pm.me> - 2026-03-18 16:34 -0500
Re: How do I get an element of a list without it being substituted? Rich <rich@example.invalid> - 2026-03-18 20:32 +0000
Re: How do I get an element of a list without it being substituted? Choosechee <choosechee@pm.me> - 2026-03-18 16:33 -0500
Re: How do I get an element of a list without it being substituted? Rich <rich@example.invalid> - 2026-03-19 02:50 +0000
Re: How do I get an element of a list without it being substituted? Choosechee <choosechee@pm.me> - 2026-03-18 22:22 -0500
Re: How do I get an element of a list without it being substituted? Rich <rich@example.invalid> - 2026-03-19 03:55 +0000
Re: How do I get an element of a list without it being substituted? Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> - 2026-03-21 06:39 +0000
Re: How do I get an element of a list without it being substituted? Robert Heller <heller@deepsoft.com> - 2026-03-18 21:35 +0000
Re: How do I get an element of a list without it being substituted? Rich <rich@example.invalid> - 2026-03-19 02:59 +0000
Re: How do I get an element of a list without it being substituted? Emiliano <emiliano@example.invalid> - 2026-03-19 18:08 -0300
Re: How do I get an element of a list without it being substituted? Choosechee <choosechee@pm.me> - 2026-03-18 22:28 -0500
Re: How do I get an element of a list without it being substituted? Ralf Fassel <ralfixx@gmx.de> - 2026-03-19 11:11 +0100
Re: How do I get an element of a list without it being substituted? Christian Gollwitzer <auriocus@gmx.de> - 2026-03-20 08:09 +0100
csiph-web