Okay, that makes sense. So there are few things that need to change in your code. As you've already figured out, Data::Dumper isn't the tool you want to use to create tables. A good choice for that instead is Text::Table. This module will automatically adjust column sizes for you to accommodate whatever text is entered for each field.

Also, you want your code to accept multiple contact entries, looping once for each person entered. After each entry you create a hash for that person(as your code already does), and accumulate the hashes in an array. This array will hold multiple hashes, one for each person entered

Once the last person has been entered you can use Text::Table to print out this array of hashes.

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Data::Dumper; use Text::Table; # Chomp each input to remove trailing linefeed immediately sub entrada{ my ($var) = shift; print "Ingrese $var: "; my $in = <STDIN>; chomp $in; return $in; } # Return a reference to the hash that holds all of the contact informa +tion sub contact_entry { my @contact =(); my $name = entrada('Name'); my $lastName = entrada('Last Name'); my $address = entrada('Address'); my $email = entrada('Email'); my $phone = entrada('Phone Number'); my $image = entrada('Image Profile'); my $detailProfile = entrada('Detail Profile'); my %contact_entry = ( name => $name, lastName => $lastName, address => $address, email => $email, phone => $phone, image => $image, detailProfile => $detailProfile ); return \%contact_entry; } # Create a hash for each contact entered, and add it to the end of our + array my @contacts; while (1) { my $contact = contact_entry; push @contacts, $contact; print "Desea ingresar mas Contactos?[S/n]:"; my $input = <STDIN>; chomp($input); last if $input ne 's'; } # Set the header my $table = Text::Table->new( "Nombre\n======", "Apellido\n========", "E-mail\n======", "Direccion\n=========", "Telefono\n========" ); # load the data into the table, converting each hash to an array with +only the proper columns $table->load( map { [ @{$_}{qw(name lastName email address phone)} ] } @contacts ); # All done, print it out print $table;
Nombre Apellido E-mail Direccion Telefono ====== ======== ====== ========= ======== John Matt J_m@gmail Park av. 465512 Math Perry .... ..... .... Julie .... .... ..... .....

Incidentally, if you were to use Data::Dumper instead of Text::Table to print out the final array above, it would indeed be an array of 3 hashes, which looks like this:

$VAR1 = [ { 'lastName' => 'Matt', 'detailProfile' => 'detail1', 'address' => 'Park av.', 'email' => 'J_m@gmail', 'name' => 'John', 'image' => 'image1', 'phone' => '465512' }, { 'lastName' => 'Perry', 'detailProfile' => 'detail2', 'address' => '.....', 'email' => '....', 'name' => 'Math', 'image' => 'image2', 'phone' => '....' }, { 'email' => '....', 'address' => '.....', 'detailProfile' => 'detail3', 'lastName' => '....', 'image' => 'image3', 'name' => 'Julie', 'phone' => '.....' } ];

In reply to Re^3: Print Data::Dumper with format by Loops
in thread Print Data::Dumper with format by Matiasinf

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.