- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Some clarificat ion on using curly braces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-29-2010 09:00 AM
Hello,
I'm trying to work with some list vars and finding that I have to experiment with where and if I use curly braces. Not being really familiar with Tcl syntax, I was wondering if someone could just give me a brief overview of the differences between:
$var
${var}
{$var}
Thanks.
Re: Some clarificat ion on using curly braces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-29-2010 09:26 AM
$var and ${var} are identical. Braces around the variable name are used in case your variable is a complex one e.g. ${//some_xpath}.
Suppose "var" value was 5. Surrounding something will braces stops susbtitution. So when you say {$var}, it is requivalent to the string "$var" as value not "5".
So:
puts $var
will produce
5
puts ${var}
will produce
5
puts {$var}
will produce
$var
Generally to build a complex string, you can use two types of syntax:
1. one where you surround the string with double quotes e.g.
set i "lazy fox jumped over $var"
2. one where you surround the string with braces e.g.
set i {lazy fox jumped over $var}
In the first one, i will be set to 'lazy fox jumped over 5'
In the second one, i will be set to 'lazy fox jumped over $var'
Hope this makes things clear.
