问题:让Perl的
YAML::Dumper
发出{key =>“ – ”}作为键:“ – ”而不是键: –
我正在处理来自数据库行的哈希,用SOAP读取它们并将它们转换为YAML以供下一阶段使用.
第一阶段用Perl编写,并使用YAML :: Dumper生成YAML.不幸的是,对于值为“ – ”的键,裸连字符的发出没有任何引用:
$perl -e 'use YAML;use YAML::Dumper; my $ydumper=YAML::Dumper->new(); print $ydumper->dump({key1=>1,key2=>"-",key3=>3});' --- key1: 1 key2: - key3: 3
下一阶段,读取上述内容并对其进行进一步操作,在Ruby中.原始破折号导致Ruby的YAML解析器变为varf:
$ruby -rubygems -ryaml -e 'YAML.load($stdin.read);' # assume the above piped in /usr/share/ruby/vendor_ruby/psych.rb:205:in `parse': (<unkNown>): block sequence entries are not allowed in this context at line 3 column 7 (Psych::SyntaxError) from /usr/share/ruby/vendor_ruby/psych.rb:205:in `parse_stream' from /usr/share/ruby/vendor_ruby/psych.rb:153:in `parse' from /usr/share/ruby/vendor_ruby/psych.rb:129:in `load' from -e:1:in `<main>'
我的问题很简单:如何指示YAML :: Dumper将短划线作为带引号的字符串发出?
谢谢!