#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $file = "C:/Documents and Settings/franciscor/Desktop/Kindergarten.txt"; open my $fh, '<', $file or die("Error opening file $!"); my %students_51; my %students_53; until ( eof($fh) ) { chomp( my $name = <$fh> ); chomp( my $age = <$fh> ); chomp( my $topic = <$fh> ); chomp( my $class = <$fh> ); if ( $class == 2051 ) { $students_51{$name}->{'age'} = $age; $students_51{$name}->{'topic'} = $topic; $students_51{$name}->{'class'} = $class; } elsif ( $class == 2053 ) { $students_53{$name}->{'age'} = $age; $students_53{$name}->{'topic'} = $topic; $students_53{$name}->{'class'} = $class; } } close $fh; print Dumper(\%students_51,\%students_53); use Text::Table; my $table_51 = Text::Table->new( "NAME\n-----", "AGE\n---", "TOPIC\n-----", "CLASS\n-----" ); foreach my $key ( keys %students_51 ) { #Direct interpolation to the add function of Text::Table $table_51->add( $key, "$students_51{$key}->{'age'}", "$students_51{$key}->{topic}", "$students_51{$key}->{class}" ); } $table_51->add(' '); #ADD AN EMPTY LINE print $table_51; #since we are using a bulk loader we don't need to loop through %students_53 #Of course this is inefficient if your table has many rows and columns my $table_53 = Text::Table->new( "NAME\n-----", "AGE\n---", "TOPIC\n-----", "CLASS\n-----" ); my @Zuxu_data = ( "Zuxo", " ", " ", "2053" ); $table_53->load( [ "Bith", "$students_53{Bith}->{'age'}", "$students_53{Bith}->{'topic'}", "$students_53{Bith}->{'class'}" ], [ "Lylek", "$students_53{Lylek}->{'age'}", "$students_53{Lylek}->{'topic'}", "$students_53{Lylek}->{'class'}" ], [ "Massiff", "$students_53{Massiff}->{'age'}", "$students_53{Massiff}->{'topic'}", "$students_53{Massiff}->{'class'}" ], \@Zuxu_data ); print $table_53;