#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $output_file = 'OUTPUT_FILE'; ## output file name GetOptions( 'file1=s' => \my $file1, 'file2=s' => \my $file2, 'file3=s' => \my $file3 ); open my $fh1, '<', $file1 or die "Can't open $file1: $!"; # file1 list by user output list open my $fh2, '<', $file2 or die "Can't open $file2: $!"; # XX.file2 file # can make this as an option 1st... my @array_1 = <$fh2>; my @array_2; while ( <$fh1> ) { ## my config file next unless /\S/; my ( $input, $output ) = split; for ( @array_1 ) { next unless /\S/; next unless /\Q$output/ && /\Q$input/; # print out all the matching output lines my @V_output = ( split )[ 7, 2, 3 ]; my %stages = ( split )[ 11, 13, 15, 17, 19, 21, 23, 25 ]; for my $key ( grep /\Q$input/, keys %stages ) { push @array_2, "$key @V_output $stages{$key}"; last; } } } open my $fh3, '<', $file3 or die "Can't open $file3: $!"; # xx.file3 file my @array_3 = <$fh3>; my @array_4; for ( @array_2 ) { my @data_1 = split; for ( @array_3 ) { my @data_2 = ( split )[ 3, 4, 7, 9 ]; if ( $data_2[ 0 ] == $data_1[ 2 ] && $data_2[ 0 ] == $data_1[ 3 ] ) { push @array_4, "@data_1 @data_2"; } } } my @array_5; for ( @array_4 ) { my @data = split; for ( @array_1 ) { my ( $marc_data, $marc_add, $output, $input, $stage ) = ( split )[ 2, 3, 7, 11, 13 ]; if ( $output =~ /\Q$data[1]/ ) { if ( $input =~ /\Q$data[0]/ && $stage =~ /\Q$data[1]/ ) { push @array_5, "@data N/A N/A"; } elsif ( $input =~ /\Q$data[4]/ && $stage =~ /\Q$data[1]/ ) { push @array_5, "@data $marc_data $marc_add"; } } } } my @array_6; for ( @array_5 ) { my @data = split; for ( @array_3 ) { my ( $file3_data, $file3_add, $dataout, $marc_array ) = ( split )[ 3, 4, 7, 9 ]; if ( 'N/A' =~ /$data[9]/ && 'N/A' =~ /$data[10]/ ) { push @array_6, "@data N/A N/A"; last; } elsif ( $file3_data =~ /$data[9]/ && $file3_add =~ /$data[10]/ ) { push @array_6, "@data $dataout $marc_array"; last; } } } open my $fh4, '>', $output_file or die "Can't open $output_file: $!"; #output file print $fh4 <<'HEADER'; STAGE_N STAGE_N+1 <<<<<>>>>>>>. <<<<>>>>>> <<<>><<<<<>>>>>>>>>>>>>><<<<<<<<<<<<<>>>>>>>>>>><<<<>>>><<<<>>>>>>>>>>>>>>><<<<<<<>>>>>>>>>>> DATA ADD DATA ADD HEADER printf $fh4 "%-25s %12s %4s %6s %-30s %30s %2s %4s %20s %20s\n", ( split )[ 0 .. 3, 7 .. 12 ] for @array_6;