YAML :: Dumper not quoting scalar string "-"
Problem: Getting Perl YAML::Dumperfor emit {key=>"-"}as key: "-", rather thankey: -
I process the hashes from the database rows, reading them using SOAP and turning them into YAML for consumption in the next step.
The first step is written in Perl and generates YAML with YAML::Dumper. Unfortunately, for keys that matter "-", a bare hyphen is emitted without quoting:
$ 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
The next step, which reads above and performs further manipulations with it, is in Ruby. An unprocessed dash causes the Ruby YAML parser to equal 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>'
My question is simple: how can I instruct to YAML::Dumperemit a dash as a quoted string?
Thank!