|
|
Subject: Generating input files from table of values; (-) signs get omitted
From: Glenn Jackman
Date: 11/8/2007 2:10:56 PM
At 2007-11-07 03:28PM, "gcm2008@mac.com" wrote:
> inherited a Tk/Tcl script that does exactly this, with one problem. If
> the value to be substituted is negative (-), the minus sign is omitted
> in the new input file!
>
> Here's a snippet of the code.
[...]
> set tempbaseline [read $baselinefid]
>
> # Substitute new values into input file contents string
> set tempbaseline [string map "\"one\" $var2" $tempbaseline]
> set tempbaseline [string map "\"two\" $var3" $tempbaseline]
> set tempbaseline [string map "\"three\" $var4" $tempbaseline]
> set tempbaseline [string map "\"four\" $var5" $tempbaseline
> ]
That quoting is pretty awkward. You could try:
set tempbaseline [string map [list one $var2 two $var3 three $var3 four $var4] $tempbaseline
or, to avoid long lines:
set tempbaseline [string map [list \
one $var2 \
two $var3 \
three $var3 \
four $var4 \
] $tempbaseline
> In the above, if the 20th value of $var2 is "-123.45", then cases/
> input20.dat will have the line containing "one" replaced with "123.45"
> which is correct, except for the missing minus sign.
I don't see what you claim. There must be something you haven't shown
us that is the culprit.
% set tempbaseline "one two three four"
one two three four
% foreach {var2 var3 var4 var5} {123 -222 -333 444} break
% string map [list one $var2 two $var3 three $var3 four $var4] $tempbaseline
123 -222 -333 444
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
|