Good Afternoon Monks, I have come to a hard stop because I cannot figure out how to order these numbers in order from least to greater...
my little program checks between 2 files that contain numbers in different languages then matches those that are found in both then prints them. otherwise, it dumps them into another where the key wasn't found in either.
But now, I wanted to order the output in numerical order(learning perl still so I build on this stuff)
Experiment 1suppose the input file (contains the keys) have the numbers in numerical order. I've been thinking of taking the line number they are found then attach this to the hash somehow...But I don't know how. Any help/advice/hints will be helpful.
Experiment 2the input file does NOT contain the numbers in any order. I suppose I need to check the keys in the hash against to some table to cross check the order of keys before outputting. I don't know how to do this either. hints on how to do this?
Ordered numbers (later will be scrambled)
uno = uno
due = dos,zwei
tre = tres,drei
quattro = quatro
cinque = cinco,funf
sei = seis,
sette = siete,sechs
otto = ocho
nouve = nueve, neun
dieci = diez, zehn
undici = once, elf
dodici = doce
tredici = trece, dreizehn
2nd file
uno = un, one
due =deux, two,
tre = trois,drei, three
quattro = quatre,four
cinque = cinq,funf, five
sei = six , six
sette = sept , seven ,sechs
dieci =dix
undici = onze,eleven
tredici = treize,thirteen, dreizehn
Program
use strict;
use diagnostics;
use warnings;
use autodie qw(open close);
use Data::Dump qw(dump);
#declare variables
my %hash;
my $data;
#opening Files using autodie to cut typing...
open my $in, '<',"./Test_Data_RandNumbers.txt";
open my $in1,'<',"./Test_Data_More_RandNumbers.txt";
open my $out ,'>' ,"./OUT_Test_Data_Ita_SpanFren_rest.txt";
open my $out1,'>',"./OUT_Test_data_NO_match_SpanFren.txt";
while (<$in>){
#data manipulation to clean up ='s and ,'s
#dieci = diez, zehn -->worse case, remove spaces and = and comm
+a;
#quattro = quatro -->only one number with spaces or not in from of
+ =...
chomp;
my ($ita,$spa,$num)= split(/[=\s,]+/); # removes '=' or 's' or ','
+ & '+' to match 1 or more these characters
$hash{$ita}[0]=$spa;
#what about if there is no $num at position 1 in 1st file?
if (defined $num){
$hash{$ita}[2]=$num; # if defined then keep it for check l
+ater in position 2 in array
}
}
close $in;
while (<$in1>){
chomp;
my ($ita,$fren,$num1,$num2)= split(/[=\s,]+/); #creates col of num
+bers
$hash{$ita}[1]=$fren; #now hashs format will look like this: ita=>
+ spa fren
#define if there is are numbers in position 3 and 4 concat to posi
+tion 3
if (defined ($num1) and defined ($num2)){
$hash{$ita}[3]=$num1.$num2; # concat if numbers defined in poitio
+n 1 and 2 and store in 3
} elsif(defined $num1) {
$hash{$ita}[3]=$num1; #if array has num in pos 2 then sa
+ve number in position 3(dieci)
}
}
close $in1;
foreach my $ita (keys %hash){
if($hash{$ita}[0] and $hash{$ita}[1]){
print $out "$ita =>", join(',',@{$hash{$ita}}),"\n";
}else {
print $out1 "$ita =>",join(',',@{$hash{$ita}}),"\n";
}
}
close $out;
close $out1;