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


In reply to Re^3: rectangularizing input to become array by johngg
in thread rectangularizing input to become array by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.