Parse a Tcl variable name inside a string



Hi,
I would like to parse variable names from a string.
Let's assume I have the following variable set
set myvar {text_$var1_text_$var2}

The $var1 and $var2 must not be replaced immediately by their values.
Now if I do the following
set var1 12
set var2 25
puts [subst $myvar]

I get "text_12_text_25", this is what I expect.
Sometimes, var1 might not be set before the "subst $myvar" command,
leading to a crash.
I would like to parse the variable myvar before trying to subst it, in
order to find out that it requires the variables var1 and var2 to be
defined, and then check var1 and var2.
Now, my problems : the names "var1" and "var2" can change, and even
the number of sub-variables.
Moreover, the syntax $var or ${var} might be used.

I think I could use regexps, but how can handle the changing number of
matches ?
Thanks for your help
Philippe

.



Relevant Pages

  • Re: Parse a Tcl variable name inside a string
    ... set myvar ... The $var1 and $var2 must not be replaced immediately by their values. ... Sometimes, var1 might not be set before the "subst $myvar" command, ...
    (comp.lang.tcl)
  • Re: Parse a Tcl variable name inside a string
    ... set myvar ... The $var1 and $var2 must not be replaced immediately by their values. ... Sometimes, var1 might not be set before the "subst $myvar" command, ...
    (comp.lang.tcl)
  • Re: Parse a Tcl variable name inside a string
    ... I would like to parse variable names from a string. ... set myvar ... The $var1 and $var2 must not be replaced immediately by their values. ...
    (comp.lang.tcl)
  • Re: Parse a Tcl variable name inside a string
    ... I would like to parse variable names from a string. ... set myvar ... puts [subst $myvar] ... won't work because tcl doesn't know you mean $var1 rather than $var1_text_) ...
    (comp.lang.tcl)
  • Re: [PHP] string as file
    ... This is an example of $var1 and $var2. ... I think that neither you nor Greg understands what I'm looking for. ... Use regular expressions or straight string replacements - that's the best way to implement mail-merge type behaviour. ...
    (php.general)