in reply to Re^2: rectangularizing input to become array
in thread rectangularizing input to become array
Unlike Dumper(), Data::Dumper->Dump() and ->Dumpxs() are not exported by Data::Dumper. However, for a little extra effort they do provide clearer output, especially if examining multiple data structures. They allow you to distinguish arrays and references to arrays, ditto for hashes. Many Monks recommend and use the more modern and flexible Data::Dump module but Data::Dumper has the advantage of being in core from way back so is useful if maintaining elderly servers in a closed environment running, say, Perl 5.8 or even earlier. Here is a simple example.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MData::Dumper -E + ' my @names = qw{ Fred Joe Mary }; my %staff = ( Fred => { age => 31, role => q{clerk} }, Joe => { age => 47, role => q{janitor} }, Mary => { age => 33, role => q{manager} }, ); my $roles = [ qw{ clerk janitor manager technician } ]; print Dumper( @names, %staff, $roles ); say q{-} x 20; print Dumper( \ @names, \ %staff, $roles ); say q{-} x 20; print Data::Dumper->Dumpxs( [ \ @names, \ %staff, $roles ], [ qw{ *nam +es *staff roles } ] );' $VAR1 = 'Fred'; $VAR2 = 'Joe'; $VAR3 = 'Mary'; $VAR4 = 'Joe'; $VAR5 = { 'role' => 'janitor', 'age' => 47 }; $VAR6 = 'Fred'; $VAR7 = { 'role' => 'clerk', 'age' => 31 }; $VAR8 = 'Mary'; $VAR9 = { 'role' => 'manager', 'age' => 33 }; $VAR10 = [ 'clerk', 'janitor', 'manager', 'technician' ]; -------------------- $VAR1 = [ 'Fred', 'Joe', 'Mary' ]; $VAR2 = { 'Joe' => { 'role' => 'janitor', 'age' => 47 }, 'Fred' => { 'role' => 'clerk', 'age' => 31 }, 'Mary' => { 'role' => 'manager', 'age' => 33 } }; $VAR3 = [ 'clerk', 'janitor', 'manager', 'technician' ]; -------------------- @names = ( 'Fred', 'Joe', 'Mary' ); %staff = ( 'Joe' => { 'role' => 'janitor', 'age' => 47 }, 'Fred' => { 'role' => 'clerk', 'age' => 31 }, 'Mary' => { 'role' => 'manager', 'age' => 33 } ); $roles = [ 'clerk', 'janitor', 'manager', 'technician' ];
I hope this is helpful.
Cheers,
JohnGG
|
|---|