我有一个tcl脚本正在捕获一些数据。我想将此数据写入YAML文件。我可以阅读有关在TCL中执行此操作的任何示例或地方吗?
Tcllib中的yaml
软件包可以做到这一点。
如果您的数据是一个简单的单级字典,则可以执行以下操作:
package require yaml
set yamlText [yaml::dict2yaml $yourDictionary]
例如:
% set d {foo 123 bar "this is a piece of text"}
foo 123 bar "this is a piece of text"
% yaml::dict2yaml $d
---
foo: 123
bar: this is a piece of text
%
这样做的主要问题是,它假定每个键中的所有内容实际上都是一个字符串(尽管数字通常足够短,这样也可以确定)。
因此,如果您的数据更复杂,则需要首先使用该huddle
程序包对其进行简要描述。这嵌入了生成复杂结构所需的额外类型信息。
package require huddle
package require yaml
set inner [huddle create boo "this is some text" grill "this is some other text"]
set outer [huddle create foo 123 bar $inner]
yaml::huddle2yaml $outer
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句