From Newsgroup: comp.lang.tcl
On 10/4/2024 2:01 AM, Ralf Fassel wrote:
* Colin Macleod <user7@cmacleod.me.uk.invalid>
| Luc <luc@sep.invalid> posted:
| > I am stumped by this:
| >
| > array set CONTROL {
| > InitialStartUpDir "$env(HOME)"
| > }
--<snip-snip>--
| > What am I doing wrong?
| Variable references do not get expanded inside braces {}.
| Try:
| array set CONTROL "
| InitialStartUpDir $env(HOME)
| "
Or safer, in case the expanded value contains spaces:
array set CONTROL [list InitialStartUpDir $env(HOME)]
HTH
R'
One wonders why Luc wouldn't just simply use array notation:
set ::CONTROL(InitialStartUpDir) $env(HOME)
[array set] with a list is useful when the list has more than one key/value pair, while with just a single pair takes about twice the time (as determined with [time]} to run.
BTW I have one little nitpick with the docs on this one. It states:
"Each odd-numbered element in list is treated as an element name within arrayName ..."
In Tcl, list indices invariably begin at 0, and yet odd-numbered here would indicate beginning at 1, and oddity in itself :)
--- Synchronet 3.20a-Linux NewsLink 1.114