You have two options: lists and arrays.
1. Using a list
In Tcl, a list is a value that contains a sequence of other (arbitrary) values. You can add things to the end of a list in a variable with lappend, and iterate over the list with foreach.
foreach ipaddress {192.168.1.3 192.168.1.4 192.168.1.5 ...} {
lappend handles [pcap open -ip $ipaddress]
}
foreach handle $handles {
# Do something with $handle here
}
2. Using an array
In Tcl, an array is a composite variable backed by an associative map (you look things up by any value you want, not necessarily a number). They can work quite well with lists.
set the_addresses {192.168.1.3 192.168.1.4 192.168.1.5 ...}
foreach ipaddress $the_addresses {
set handle($ipaddress) [pcap open -ip $ipaddress]
}
foreach ipaddress $the_addresses {
# Do something with $handle($ipaddress) here
}
Which option is best depends on the details of what you are doing.