Reputation: 3
I am trying to append the values to an array as below and it is not appending to the value list
while {[gets $fp line] != -1} {
if { [regexp {Path Group: (\w+)} $line all group]} {
set hash($group) {}
} elseif {[regexp {\(VIOLATED\)\s+(-[0-9]*.[0-9]*)} $line all slack]} {
puts "slack $slack\n"
lappend hash($group) $slack
}
}
parray hash
The output of the array hash is only the last value of the iteration bit not a list
expecting
Name { X Y Z} Age {3 4 5:}
Upvotes: 0
Views: 234
Reputation: 654
set group {}
while {[gets $fp line] != -1} {
if { [regexp {Path Group: (\w+)} $line all group]} {
} elseif {[regexp {\(VIOLATED\)\s+(-[0-9]*.[0-9]*)} $line all slack]} {
puts "slack $slack\n"
lappend hash($group) $slack
}
}
parray hash
hash($group)
on each matching because this will reset the contents of hash($group)
.lappend hash($group)
, if the variable does not exist, it will be created automatically.Upvotes: 1