Handling Trailing Colon in YAML
I'm using YAML::Tiny to write to and read from a file in Perl. Unfortunately, I'm having a problem with data that ends with a colon:
my $test_message = {"hoody" => 'hoo:'};
my $dump = YAML::Tiny::Dump($test_message);
my $reloaded = YAML::Tiny::Load($dump);
print Data::Dumper::Dumper($reloaded);
This produces Failed to load YAML document from string at [the line with YAML::Tiny::Load]
.
First off, this looks like a bug. Is it? Or am I expecting too much from YAML::Tiny? (We开发者_开发知识库're using YAML::Tiny 1.48; the newest is 1.50, which IT assures me will be installed soon.)
Second, is there any way to work around this? I'm trying to use escape characters, but I must not be doing it right. I tried replacing the colon with \x3A
, but that doesn't give the desired behavior. (Printing $dump
gives the string back unchanged [hoo\x3A
],
while the Data::Dumper::Dumper
line makes it 'hoo\\x3A'
.)
Thanks in advance for any help on this.
This bug was fixed in 1.5 You may consider using YAML instead of YAML::Tiny (Tiny version should have just the same interface as it's parent).
I think any workarounds will make things only worsen after you finally get YAML::Tiny 1.5 with bugfixes. I'd recommend you put use YAML::Tiny 1.50
in your code or switch to YAML.
精彩评论