#!/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;