• How do I correctly access this variable?

    From Luc@21:1/5 to All on Fri Oct 4 03:36:48 2024
    I am stumped by this:

    array set CONTROL {
    InitialStartUpDir "$env(HOME)"
    }

    puts $env(HOME)
    /home/luc

    OK.

    Now,

    oo::define NewTab {
    constructor {} {
    blah blah blah...
    $newtab configure -text "$::CONTROL(InitialStartUpDir)"
    }
    }

    The button label becomes "$env(HOME)" instead of /home/luc.

    What am I doing wrong?

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Colin Macleod@21:1/5 to All on Fri Oct 4 08:15:02 2024
    Luc <[email protected]d> posted:

    I am stumped by this:

    array set CONTROL {
    InitialStartUpDir "$env(HOME)"
    }

    puts $env(HOME)
    /home/luc

    OK.

    Now,

    oo::define NewTab {
    constructor {} {
    blah blah blah...
    $newtab configure -text "$::CONTROL(InitialStartUpDir)"
    }
    }

    The button label becomes "$env(HOME)" instead of /home/luc.

    What am I doing wrong?

    Variable references do not get expanded inside braces {}.
    Try:
    array set CONTROL "
    InitialStartUpDir $env(HOME)
    "

    --
    Colin Macleod.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Fri Oct 4 11:01:35 2024
    * Colin Macleod <[email protected]d>
    | Luc <[email protected]d> 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'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Ralf Fassel on Fri Oct 4 12:17:33 2024
    On 10/4/2024 2:01 AM, Ralf Fassel wrote:
    * Colin Macleod <[email protected]d>
    | Luc <[email protected]d> 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 :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)