in reply to Output only certain fields from a hash using the Data::Dumper
Hello MrSnrub,
If you want the output sorted as well as filtered, you can set $Data::Dumper::Sortkeys to do both together:
#! perl use strict; use warnings; use Data::Dumper; my %hash = (Fred => 'Wilma', Barney => 'Betty', Homer => 'Marge'); $Data::Dumper::Sortkeys = sub { [ sort grep { /^Fred|Barney$/ } keys % +{$_[0]} ] }; print Dumper \%hash;
Output:
23:01 >perl 1116_SoPW.pl $VAR1 = { 'Barney' => 'Betty', 'Fred' => 'Wilma' }; 23:01 >
(See “sorting and filtering hash keys” in Data::Dumper#EXAMPLES.) Otherwise, choroba’s approach is clearly superior.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|