#!/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 : $!"; # print the title of the columns my $titles_line = ; print OUTFILE $titles_line; # 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 OUTFILE (";" x (40-$length_1)), "\n" } } close INFILE_1; close OUTFILE;