#!/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 = ; chomp $in; return $in; } # Return a reference to the hash that holds all of the contact information 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 = ; 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 .... .... ..... ..... #### $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' => '.....' } ];