[Courses] [Basics] Lesson #2: Data (II) - Variables, Lists, and
a Loop
Dave North
dave at timocharis.com
Sat Apr 6 09:29:31 EST 2002
Sonja, thanks for the fun introduction to tcl (I've been thinking about
playing with it for some time, but didn't, and your introduction is
really a great way to get started!
However, I get a bit of weird behavior when I try the following:
> The assignment of a list to a variable is also done with 'set': >
> set list_name {"Value 1" "Value 2" "Value 3"}
> set names {"Barney" "Fred"}
Here's what comes out:
% puts "Dog"
Dog
% set animal "Dog"
Dog
% puts $animal
Dog
% set animals {"Dog" "Cat"}
"Dog" "Cat"
Note that puts prints the quotes!
% puts $animals
"Dog" "Cat"
...and again. So, just for the heck of it, I got rid of the quotes:
% set animals {Dog Cat}
Dog Cat
% puts $animals
Dog Cat
% foreach creature $animals {
puts "I have a $creature.\n"
}
I have a Dog.
I have a Cat.
%
Okay, that looks a little more like what I would have expected. Is my
interpreter doing strange things? Or do you not need quotes when assigning
a list in curly braces?
I'm running tcl8.3.3-7 on Debian Woody.
This looks like a very handy little scripting language. Thanks!
Dave North
More information about the Courses
mailing list