Re: problem with [array get ...] -> file -> string -> [array set ...]
- From: Bezoar <cwjolly@xxxxxxxxx>
- Date: Fri, 03 Aug 2007 20:45:33 -0000
On Aug 3, 2:25 pm, Greg.A.Fisc...@xxxxxxxxx wrote:
Folks,You can also use source cmd like below and the Tclx extension has an
I'm pulling my hair out trying to save and load data to a file. I've
got a large array (probably filled with all sorts of "special"
characters), here's what I'm trying:
# To save:
puts $out "RxnInfo: '[array get RxnInfo]'"
...
#
# this appears in the file as "RxnInfo: '{Np-237 nf Cs-137,corr} 1.0
{Ni-58 np Co-58,corr} 1.0 ... '
#
# To load:
while {[gets $in line] != -1} {
regexp {^(.*): '(.*)'$} $line result varname value
if {[string match "*RxnInfo*" $varname ]} {
global $varname
array set $varname [list " $value "]
}
...
I've tried every conceivable permutation of quotation marks, the list
command, and curly braces, but I can't get the $value string to load
into RxnInfo (I've tried replacing "$varname" with RxnInfo explicitly
- same thing happens). It comes back with the "list must have an even
number of elements" error. The most infuriating thing is that if I
insert "puts [list " $value "]" right above the "array set" statement,
I can take the output from the "puts" command, copy it into tclsh, and
it works no problem.
Does anyone have any idea what is going on here, and, more
importantly, can they suggest a fix? Thanks a ton.
Greg
lgets command :
---------------- START SCRIPT
#!/bin/sh
# the next line restarts using wish \
exec /opt/usr/bin/tclsh8.5 "$0" ${1+"$@"}
array set test { 1 a 2 b 3 c {abc 4} d }
parray test
puts "saving test to test.save"
# SAVING TO FILE
set fd [ open "/tmp/test.save" "w" ]
puts $fd "array set test { [ array get test] }";
close $fd
# REMOVING Test
array unset test
catch { parray test } err
puts "$err"
puts "retrieving test from test.save"
source /tmp/test.save
parray test
------------ END SCRIPT---------------
OUTPUT:
test(1) = a
test(2) = b
test(3) = c
test(abc 4) = d
saving test to test.save
"test" isn't an array
retrieving test from test.save
test(1) = a
test(2) = b
test(3) = c
test(abc 4) = d
Carl
.
- Follow-Ups:
- Re: problem with [array get ...] -> file -> string -> [array set ...]
- From: Ralf Fassel
- Re: problem with [array get ...] -> file -> string -> [array set ...]
- References:
- problem with [array get ...] -> file -> string -> [array set ...]
- From: Greg . A . Fischer
- problem with [array get ...] -> file -> string -> [array set ...]
- Prev by Date: Re: Bundling images and libraries with TclApp
- Next by Date: Re: tktable total row
- Previous by thread: Re: problem with [array get ...] -> file -> string -> [array set ...]
- Next by thread: Re: problem with [array get ...] -> file -> string -> [array set ...]
- Index(es):
Relevant Pages
|