#! perl #################################################################### # Key 0 1 2 3 4 # Italian => Spanish, French, German, English|German, English|German #################################################################### use strict; use warnings; use autodie; use constant NAMES => qw(uno due tre quattro cinque sei sette otto nouve dieci undici dodici tredici); my %hash; open my $in, '<', './Test_Data_RandNumbers.txt'; while (<$in>) { my ($ita, $spa, $ger) = split /[=\s,]+/; if ($ita) { $hash{$ita}[0] = $spa; $hash{$ita}[2] = $ger if $ger; } } close $in; open my $in1, '<', './Test_Data_More_RandNumbers.txt'; while (<$in1>) { # $num1 & $num2 may each be either English or German my ($ita, $fren, $num1, $num2) = split /[=\s,]+/; $hash{$ita}[1] = $fren; if ($num1) { $hash{$ita}[3] = $num1; $hash{$ita}[4] = $num2 if $num2; } } close $in1; open my $out , '>', './OUT_Test_Data_Ita_SpanFren_rest.txt'; open my $out1, '>', './OUT_Test_data_NO_match_SpanFren.txt'; for my $ita (sort { sort_italian() } keys %hash) { if ($ita) { my $fh = defined $hash{$ita}[0] && defined $hash{$ita}[1] ? $out : $out1; print $fh "$ita => ", join(',', map { $_ // () } @{ $hash{$ita} }), "\n"; } } close $out; close $out1; { my %numbers; BEGIN { my $i = 1; %numbers = map { $_ => $i++ } NAMES; } sub sort_italian { # Add error checking here! return $numbers{$a} <=> $numbers{$b}; } } #### if ($ita) #### if (defined $ita && $ita ne '') #### join(',', map { $_ // () } @{ $hash{$ita} }), #### Use of uninitialized value in join or string at ... line ...