Parse a Tcl variable name inside a string
- From: pmaire@xxxxxxxxx
- Date: Wed, 31 Oct 2007 05:46:16 -0700
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
.
- Follow-Ups:
- Re: Parse a Tcl variable name inside a string
- From: Bryan Oakley
- Re: Parse a Tcl variable name inside a string
- From: Arjen Markus
- Re: Parse a Tcl variable name inside a string
- Prev by Date: whats the path of menu entries within the menubar of a minwindow ( Iwidgets )
- Next by Date: Re: Parse a Tcl variable name inside a string
- Previous by thread: whats the path of menu entries within the menubar of a minwindow ( Iwidgets )
- Next by thread: Re: Parse a Tcl variable name inside a string
- Index(es):
Relevant Pages
|