need help figuring this out, I need to concat 2 numbers but I think my method is not correct ;-). shocking, I know!

#define if there (is) are numbers in position 3 and 4 concat to pos +ition 3 if (defined ($num1) and defined ($num2)){ $hash{$ita}[3]=$num1$num2; # concat if numbers defined in poition + 1 and 2 and store in 3

also, please note that italian numbers not found in both files. their output will show something like this

uno => uno, ,eins

where french is empty, how to better work this?

will hash of hashes fix the output? better method? please advise as this is my 2nd week of perl coding. 2nd week of coding anything period. still learning alot by your advice.

DATA numbers in Spanish and may be German

uno = uno,eins 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

DATA: numbers in french and maybe German or English or both

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
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"; #open my $out2,'>' , "./Test_Data_Out_None_Match.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 poition + 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;

In reply to concatenation 2 values then pushing to a hash_ref by perlynewby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.