Я пытаюсь получить список чисел из массива (в текстовом файле) и выполнить с ними математические операции, а затем вернуть их в список того же формата. Файл txt выглядит так (формат фиксирован):
1000 2000 3000 4000
Я хочу прочитать этот текстовый файл, а затем создать другой список, который будет сохранен в другом текстовом файле:
1010 1100 2010 2100 3010 3100 4010 40100 # which is basically adding 10 and 100 to each index.
Вот что я сделал до сих пор (я очень новичок в tcl!)
set zonefile [open "mytxtfile.txt" r]
gets $zonefile
set my_list [gets $zonefile]
puts $my_list
# Check that there is at least one location defined
if { [llength $my_list] == 0 } {
error "No domain are defined in the system parameters workbook"
} else {
puts "OK !"
}
puts [llength my_list]
# this returns 1, which from my understanding means I only have 1 value in my array instead of 4
set c1 [string range $my_list 0 3]
set c2 [string range $my_list 5 8]
set c3 [string range $my_list 10 13]
set c4 [string range $my_list 15 18]
array set domain_list ([lindex $c1 0] [lindex $c2 0])
# I thought this would create an array of 1000 2000 3000 4000 but this doesn't work
Большое спасибо!