Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,5 @@
set dict1 [dict create name "Rocket Skates" price 12.75 color yellow]
set dict2 [dict create price 15.25 color red year 1974]
dict for {key val} [dict merge $dict1 $dict2] {
puts "$key: $val"
}

View file

@ -0,0 +1,10 @@
set arrayname(item) $value
# or set a series of item value pairs at one time:
# create initial array
array set skates {
name {Rocket Skates}
price 12.75
color yellow
}

View file

@ -0,0 +1,39 @@
# print formatted output
proc print_array {fields arr} {
# list back to array
array set A $arr
set names [array names A]
foreach key $fields {
# format output
puts -nonewline stdout [format "%-10s" $key]
if {$key in $names} {
puts stdout [format "%-16s" $A($key)]
} else {
puts stdout ""
}
}
}
# set field order
set fields [list name price color year]
puts "skates"
print_array $fields [array get skates]
# list of updates {arrayname item value}
set updates {
{skates price 15.15}
{skates color red}
{skates year 1974}
}
# update array
foreach update $updates {
lassign $update item field value
array set $item [list $field $value]
}
puts [string repeat "-" 24]
puts "skates updated"
print_array $fields [array get skates]