R
Rud1ger Sch1erz
Hi there,
I'm fiddling around with YAML and try to write out a subset of a data
object.
The example of the YAML documentation works fine for me:
use YAML qw(Dump Bless);
use strict;
my $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'};
print Dump $hash;
Bless($hash)->keys(['banana', 'apple']);
print Dump $hash;
gives me:
---
apple: good
banana: bad
cauliflower: ugly
---
banana: bad
apple: good
But when I try to use Blessing of keys to filter and sort the output
of an object reference, YAML seems to ignore my key subset.
<code example>
#!/usr/bin/perl -w
#
{
package DailyBuildInfoSet;
sub new {
my($proto ) = @_;
my $class = ref($proto) || $proto || DailyBuildInfoSet;
my $self = {};
bless ($self, $class);
return $self;
}
sub value {
my $self = shift;
my $k = shift;
if (@_) { $self->{$k} = shift }
return $self->{$k};
}
1;
}
use YAML qw(Dump Bless);
use strict;
my $db = DailyBuildInfoSet->new();
$db->value( "DOB", '20071114' );
$db->value( "HMI_CL", '1113617' );
$db->value( "TC_CL", '1111316' );
print Dump $db;
Bless($db)->keys(['HMI_CL', 'TC_CL']);
print Dump $db;
</code example>
Output of this example is:
$ t3.Al
--- !!perl/hashailyBuildInfoSet
DOB: 20071114
HMI_CL: 1113617
TC_CL: 1111316
--- !!perl/hashailyBuildInfoSet
DOB: 20071114
HMI_CL: 1113617
TC_CL: 1111316
On the latter, I would expect (and like to have):
--- !!perl/hashailyBuildInfoSet
HMI_CL: 1113617
TC_CL: 1111316
BTW, perl -v gives me:
This is perl, v5.8.8 built for cygwin-thread-multi-64int
(with 8 registered patches, see perl -V for more detail)
Could some kind soul point me to the reason, why YAML seems to ignore
my key blessing?
Cheers,
Rudiger
I'm fiddling around with YAML and try to write out a subset of a data
object.
The example of the YAML documentation works fine for me:
use YAML qw(Dump Bless);
use strict;
my $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'};
print Dump $hash;
Bless($hash)->keys(['banana', 'apple']);
print Dump $hash;
gives me:
---
apple: good
banana: bad
cauliflower: ugly
---
banana: bad
apple: good
But when I try to use Blessing of keys to filter and sort the output
of an object reference, YAML seems to ignore my key subset.
<code example>
#!/usr/bin/perl -w
#
{
package DailyBuildInfoSet;
sub new {
my($proto ) = @_;
my $class = ref($proto) || $proto || DailyBuildInfoSet;
my $self = {};
bless ($self, $class);
return $self;
}
sub value {
my $self = shift;
my $k = shift;
if (@_) { $self->{$k} = shift }
return $self->{$k};
}
1;
}
use YAML qw(Dump Bless);
use strict;
my $db = DailyBuildInfoSet->new();
$db->value( "DOB", '20071114' );
$db->value( "HMI_CL", '1113617' );
$db->value( "TC_CL", '1111316' );
print Dump $db;
Bless($db)->keys(['HMI_CL', 'TC_CL']);
print Dump $db;
</code example>
Output of this example is:
$ t3.Al
--- !!perl/hashailyBuildInfoSet
DOB: 20071114
HMI_CL: 1113617
TC_CL: 1111316
--- !!perl/hashailyBuildInfoSet
DOB: 20071114
HMI_CL: 1113617
TC_CL: 1111316
On the latter, I would expect (and like to have):
--- !!perl/hashailyBuildInfoSet
HMI_CL: 1113617
TC_CL: 1111316
BTW, perl -v gives me:
This is perl, v5.8.8 built for cygwin-thread-multi-64int
(with 8 registered patches, see perl -V for more detail)
Could some kind soul point me to the reason, why YAML seems to ignore
my key blessing?
Cheers,
Rudiger