TCL evaluation curly brace that is part of my variable value 
Author Message
 TCL evaluation curly brace that is part of my variable value

Hi,

I have a variable with a curly brace inside of it, like so:
        set str "-echo \"~m2\" {"

When I foreach over a list of variables like this, it tells me that an
unmatched open brace is in the list.  How can I get so that Tcl wont
evaluate that curly brace?  There is really no good way I can think of
to remove the curly brace from the value...

Thanks.

-dmp



Wed, 19 Dec 2007 15:53:30 GMT  
 TCL evaluation curly brace that is part of my variable value
Quote:

> I have a variable with a curly brace inside of it, like so:
> set str "-echo \"~m2\" {"

> When I foreach over a list of variables like this, it tells me that an
> unmatched open brace is in the list.  How can I get so that Tcl wont
> evaluate that curly brace?

Tcl doesn't evaluate the curly brace unless you tell it to:

tclsh (1) > set str "-echo \"~m2\" {"
-echo "~m2" {
tclsh (2) > set list [list $str $str $str]
-echo\ \"~m2\"\ \{ -echo\ \"~m2\"\ \{ -echo\ \"~m2\"\ \{
tclsh (3) > foreach s $list {
puts $s

Quote:
}

-echo "~m2" {
-echo "~m2" {
-echo "~m2" {

So you must be doing something more, or different than what you described.
Can you share a short piece of code that shows the problem?

Schelte.
--
set Reply-To [string map {nospam schelte} $header(From)]



Wed, 19 Dec 2007 17:55:36 GMT  
 TCL evaluation curly brace that is part of my variable value

Quote:

>> I have a variable with a curly brace inside of it, like so:
>> set str "-echo \"~m2\" {"

>> When I foreach over a list of variables like this, it tells me that an
>> unmatched open brace is in the list.  How can I get so that Tcl wont
>> evaluate that curly brace?
> Tcl doesn't evaluate the curly brace unless you tell it to:

> tclsh (1) > set str "-echo \"~m2\" {"
> -echo "~m2" {
> tclsh (2) > set list [list $str $str $str]
> -echo\ \"~m2\"\ \{ -echo\ \"~m2\"\ \{ -echo\ \"~m2\"\ \{
> tclsh (3) > foreach s $list {
> puts $s
> }
> -echo "~m2" {
> -echo "~m2" {
> -echo "~m2" {

> So you must be doing something more, or different than what you described.
> Can you share a short piece of code that shows the problem?

> Schelte.

Hmmm, ok I am using exec to grep for all lines that have a ~ in it from
a file.  So:

-echo "~commands" {
                set commandBuffer [exec grep "~" $EXECUTABLE]
                puts $commandBuffer
                foreach line $commandBuffer {
                        puts "LINE = $line"
                        regexp "(~\[a-zA-Z]+)" $line match command
                        puts "$command"
                }
        }

Quote:
}

Whenever I do this, I get this:

Mars_42:admin> ~commands        -echo "~schi" {getLuns "schi"}
        -echo "~scem" {getLuns "scem"}
        -echo "~ibA" {getLuns "ibA"}
        -echo "~ibB" {getLuns "ibB"}
        -echo "~msaA" {getLuns "msaA"}
        -echo "~msaB" {getLuns "msaB"}
        -echo "~cx" {getLuns "cx"}
        -echo "~xp1a" {getLuns "xp1a"}
        -echo "~xp5a" {getLuns "xp5a"}
        -echo "~axA" {getLuns "axA"}
        -echo "~axB" {getLuns "axB"}
        -echo "~axC" {getLuns "axC"}
        -echo "~axD" {getLuns "axD"}
        -echo "~hsgA" {getLuns "hsgA"}
        -echo "~hsgB" {getLuns "hsgB"}
        -echo "~dmx" {getLuns "dmx"}
        -echo "~hitA" {getLuns "hitA"}
        -echo "~hitB" {getLuns "hitB"}
        -echo "~hitC" {getLuns "hitC"}
        -echo "~hitD" {getLuns "hitD"}
        -echo "~h9ba" {getLuns "h9ba"}
        -echo "~h9bb" {getLuns "h9bb"}
        -echo "~bA" {getLuns "bA"}
        -echo "~bB" {getLuns "bB"}
        -echo "~bC" {getLuns "bC"}
        -echo "~bD" {getLuns "bD"}
        -echo "~bE" {getLuns "bE"}
        -echo "~bF" {getLuns "bF"}
        -echo "~bG" {getLuns "bG"}
        -echo "~bH" {getLuns "bH"}
        -echo "~evaA" {getLuns "evaA"}
        -echo "~evaB" {getLuns "evaB"}
        -echo "~evaC" {getLuns "evaC"}
        -echo "~evaD" {getLuns "evaD"}
        -echo "~all" {
        -echo "~commands" {
                set commandBuffer [exec grep "~" $EXECUTABLE]
                        regexp "(~\[a-zA-Z]+)" $line match command
        -echo "~infoluns" {
        -echo "~infowwn" {
        -echo "~infounused" {
        -echo "~infoglobals" {
        -echo -re "~l(\[0-9a-zA-Z]+)\r" {
        -echo "~lall"  {
        -echo "~test" {
        -echo -re "~ep-(\[a-zA-Z0-9]+)-(\[a-zA-Z0-9]+)\r" {
        -echo "~wipelupaths" {
        -echo "~wipeextents" {
        -echo "~wipeepair" {
        -echo "~wipemset" {
        -echo "~restart" {
        -echo "~tail" {
        -echo "~m1" {
        -echo "~m2" {
        -echo "~m3" {
        -echo "~m4" {
        -echo "~mall" {
        -echo "~start" {
        -echo "~perf10" {
        -echo "~perf20" {
unmatched open brace in list
    while executing
"foreach line $commandBuffer {
                        puts "LINE = $line"
                        regexp "(~\[a-zA-Z]+)" $line match command
                        puts "$command"
                }"
    invoked from within
"interact -nobrace -echo ~schi {getLuns "schi"} -echo ~scem {getLuns
"scem"} -echo ~ibA {getLuns "ibA"} -echo ~ibB {getLuns "ibB"} -echo
~msaA {getLuns..."
    invoked from within

I don't this is a list so maybe I shouldnt be foreaching over it?



Thu, 20 Dec 2007 02:30:18 GMT  
 TCL evaluation curly brace that is part of my variable value

Quote:

>                 set commandBuffer [exec grep "~" $EXECUTABLE]
>                 puts $commandBuffer
>                 foreach line $commandBuffer {
>                         puts "LINE = $line"
>                         regexp "(~\[a-zA-Z]+)" $line match command
>                         puts "$command"
>                 }

You are treating the commandBuffer variable as if it is a list, which it
isn't. But you can easily turn it into a list.

Judging from the name of the loop variable you want each list element to be
a single line, right? So try this:

    set commandBuffer [exec grep "~" $EXECUTABLE]
    puts $commandBuffer
    foreach line [split $commandBuffer \n] {
        puts "LINE = $line"
        regexp "(~\[a-zA-Z]+)" $line match command
        puts "$command"
    }

Schelte
--
set Reply-To [string map {nospam schelte} $header(From)]



Thu, 20 Dec 2007 03:20:00 GMT  
 TCL evaluation curly brace that is part of my variable value

Quote:

> I have a variable with a curly brace inside of it, like so:
>     set str "-echo \"~m2\" {"

> When I foreach over a list of variables like this, it tells me that an
> unmatched open brace is in the list.  How can I get so that Tcl wont
> evaluate that curly brace?  There is really no good way I can think of
> to remove the curly brace from the value...

If you want to do list ops on it, then you should create the
var with a [list ...] construct, otherwise only do string
ops on it.

--
   Jeff Hobbs, The Tcl Guy
   http://www.ActiveState.com/, a division of Sophos



Fri, 21 Dec 2007 01:02:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Order of evaluation with curly braces within quotes

2. Tcl Performance, those dang curly braces (FAQ item?)

3. curly braces and trim missing in VW

4. curly braces for "for"?

5. Inserting '\t;' between empty curly braces

6. curly-brace-aphobic?

7. Curly braces

8. lrange drops curly brace

9. remove curly braces

10. Newbie question about curly braces

11. How prevent curly braces in text output

12. Curly braces and comments

 

 
Powered by phpBB® Forum Software