#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); use constant ARGUMENTS => scalar 2; $| = 1; my @timestamp_first; my @timestamp_second; my $write = 'output.txt'; sub first { open (FIRST, "<" , $ARGV[0]) or die ("Could not open: ".$ARGV[0]." - $!\n"); while ( my @first_read = ) { chomp @first_read; foreach $_ (@first_read) { my @result_first = split (':', $_); if (/^\s*$/) { # /^\s*$/ check for "blank" lines may contain spaces or tabs next; } push (@timestamp_first, $result_first[3]); } } close (FIRST) or die ("Could not close: ".$ARGV[0]." - $!\n"); return @timestamp_first; } sub second { open (SECOND, "<" , $ARGV[1]) or die ("Could not open: ".$ARGV[1]." - $!\n"); while ( my @second_read = ) { chomp @second_read; foreach $_ (@second_read) { my @result_second = split (':', $_); if (/^\s*$/) { # /^\s*$/ check for "blank" lines may contain spaces or tabs next; } push (@timestamp_second, $result_second[3]); } } close (SECOND) or die ("Could not close: ".$ARGV[1]." - $!\n"); return @timestamp_second; } sub write { open (WRITE , ">>" , $write ) or die ("Could not open: ".$write." - $!\n"); foreach $_ (@_) { print WRITE $_ . "\n"; } close (WRITE) or die ("Could not close: ".$write." - $!\n"); my $text = "Successfully writen on ".$write.".\n"; return ($text); } sub check { if (@ARGV < ARGUMENTS || @ARGV > ARGUMENTS) { die "Please enter ".ARGUMENTS." files to read!\n"; } } &check(@ARGV); my @first_values = &first($ARGV[0]); my @second_values = &second($ARGV[1]); my @final; my $num = @first_values; for($_ = 0; $_ < $num; $_++) { push (@final , $first_values[$_] . ' ' . $second_values[$_]); } print Dumper (\@final); my $date = time(); my $output = &write(@final); print "\nResult: ".$output."";