08:49:43;DAL11;08:10;08:30;08:30;08:39;08:47;08:47;08:50;;;;;05:03:00;08:10;-187;;08:30;0;0;;;;;;;;
####
DAL11;DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:39;339
####
08:49:43;DAL11;08:10;08:30;08:30;08:39;08:47;08:47;08:50;;;;;05:03:00;08:10;-187;;08:30;0;0;;;;;;;;
DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:39;339
####
08:49:43;DAL11;08:10;08:30;08:30;08:39;08:47;08:47;08:50;;;;;05:03:00;08:10;-187;;08:30;0;0;;;;;;;;DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:39;339
####
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Cwd;
# display current working directory
my $Current_Dir = getcwd;
print STDOUT "the current directory is $Current_Dir\n";
# input files to work on
my $file_1 = "$ARGV[0]";
my $file_2 = "$ARGV[1]";
my $outfile = "outfile_$file_1";
# open files
open INFILE_1, '<', $file_1, or die "Can't open $file_1 : $!";
open INFILE_2, '<', $file_2, or die "Can't open ${file_2} : $!";
open OUTFILE, '>', $outfile, or die "Can't open $outfile : $!";
# create hash of aircraft specific data from file 2
my %aircraftID;
while (my $line_2 = ){
chomp($line_2);
my @Elements_2 = split ';', $line_2;
my $aircraft_id_2 = shift @Elements_2;
$aircraftID{$aircraft_id_2} = \@Elements_2;
}
close INFILE_2;
# read each line of file1 and look for aircraft
while (my $line_1 = ){
chomp($line_1);
my @Elements_1 = split ';', $line_1;
my $aircraft_id_1 = $Elements_1[1];
my $length_1 = @Elements_1;
# monitor the process
print STDOUT "the length is $length_1\n";
print STDOUT "The Table is @Elements_1\n";
# print the current line into the output file
print OUTFILE "$line_1";
# if the line contains an aircraft ID, search for its data in file 2
if ($aircraft_id_1 && exists $aircraftID{$aircraft_id_1}) {
print OUTFILE join(';',@{$aircraftID{$aircraft_id_1}}), "\n";
} else { print "\n" }
}
close INFILE_1;
close OUTFILE;