1

I have a yaml file which looks like this:

---
date: 25-01-2010
version: 0.1

I want to edit it. I using this code:

use YAML::XS qw(LoadFile);
use YAML::Syck qw(Dump);    

my $list = LoadFile("config.yaml");
$list{date} = "12-11-2011";
print "The date is $list->{date} \n";
print "The version is $list->{version} \n";
open F, '>', "config.yaml";
print F Dump( \%list );
close F;
}

and when it's done my yaml file contains only date and empty line in the end.

--- 
date: 12-11-2011

What's wrong with this code? if I checking value version before writing I getting good result, it's showing version but it doesn't write it at all...

I tried to use YAML::Syck::DumbFile but file after writing wasnt contain version too, and it was look like this :

---
date:
12-11-2011
Alex Zheludov
  • 171
  • 5
  • 17

1 Answers1

9

You are loading the YAML into $list. Then, you are setting 'date' in the hash %list (a completely different variable, which is initialized empty), and dumping that.

${$list}{date} = '12-11-2011';
print Dump($list);

You should read perlreftut and

use strict;

ephemient
  • 198,619
  • 38
  • 280
  • 391