Subject: | Upon Dump(), all hashes within data have their 'each' iterator exhausted |
See attached file. Very simply, after you call Dump() on a data
structure, all hashes within that structure will have their 'each'
iterator exhausted. This means that, if you call:
my $str = Dump($data);
while (my ($key, $value) = each %{ $data->{hash} }) {
# do something
}
The 'do something' will never happen. A work around (not really) is to
either a) avoid using 'each', or b) reset the iterator by calling 'keys'
or 'values' on the hash.
Eric Waters
Subject: | test.pl |
#!/usr/bin/perl
use strict;
use warnings;
use YAML::XS qw(Dump Load);
my %hash = (
eric => 'waters',
subhash => {
jason => 'hansen',
},
);
my $str = Dump(\%hash);
## The following code won't run, as each will return undef
## FIXME!!!
while (my ($key, $value) = each %hash) {
print $key . ': ';
if (ref($value)) {
print "\n";
while (my ($skey, $svalue) = each %$value) {
print $skey . ': ' . $svalue . "\n";
}
}
else {
print $value . "\n";
}
}