-
Notifications
You must be signed in to change notification settings - Fork 589
Open
Description
This is an enhancement suggestion.
Currently a hash member is shown for every key returned by a Sortkeys sub even if there is no such member. The output shows non-existent members as existing with an undef value.
It would be nice (and arguably more correct) to omit hash members which don't actually exist.
To get a correct display, one currently must do something like
Data::Dumper->new([$href])->Sortkeys(sub{ [ grep{ exists($_[0]->{$_}) } qw/all possible keys/]}->Dump
Whereas it would be nice to be able to just say
Data::Dumper->new([$href])->Sortkeys(sub{[qw/all possible keys/]}->Dump
Demo program:
#!/usr/bin/perl
use strict; use warnings; use feature qw/say/;
use Data::Dumper;
my $href1 = { aaa => 100 };
my $href2 = { aaa => 100, OPTIONAL => undef };
say Data::Dumper->new([$href1, $href2],['href1','href2'])->Sortkeys(sub{[qw/OPTIONAL aaa bbb/]})->Dump;
Current results:
$href1 = {
'OPTIONAL' => undef,
'aaa' => 100,
'bbb' => undef
};
$href2 = {
'OPTIONAL' => undef,
'aaa' => 100,
'bbb' => undef
};
Desired results:
$href1 = {
'aaa' => 100,
'bbb' => undef
};
$href2 = {
'OPTIONAL' => undef,
'aaa' => 100,
'bbb' => undef
};
Metadata
Metadata
Assignees
Labels
No labels