#!/usr/bin/perl use strict; use warnings; use Text::Table; use Tie::IxHash; use Fcntl qw( :flock ); use List::Util qw( max ); use POSIX qw( strftime ); use Data::Dumper qw( Dumper ); use constant ARGUMENTS => scalar 1; $| = 1; my ($value , $table); my %hash = (); sub hash_sub { foreach my $arg (@_) { open ( READ, "<" , $arg ) or die ("Could not open: ".$arg." - $!\n"); flock( READ , LOCK_EX ) or die "Could not lock '".$arg."' - $!\n"; if (-z "".$arg."") { print "File '".$arg."' is empty!\n"; # -z File has zero size (is empty). } my @doc_read = ; chomp @doc_read; foreach $_ (@doc_read) { my @result = split (':', $_); if (/^\s*$/) { # /^\s*$/ check for "blank" lines may contain spaces or tabs next; } push (@$value , $result[3]); } $hash{$arg} = $value; $value = (); # emptying the string_ref for the next ARGV close (READ) or die ("Could not close: ".$arg." - $!\n"); } my $max_idx = max map $#$_ , values %hash; my $tb = Text::Table->new; foreach my $i (0 .. $max_idx) { $tb->add( $i + 1 . ' ' , map $hash{$_}[$i] , sort keys %hash ); } return $tb; } $table = hash_sub(@ARGV); print $table;