Hello perlynewby,

Since the input data will “later be scrambled,” there doesn’t seem to be much point in pursuing the strategy of Experiment 1. I have therefore looked only at Experiment 2, using a hash for lookup. The resulting code is far from perfect, but it produces the desired output:

#! 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 nou +ve 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}; } }

Some notes:

Hope that helps,

Updates: Made minor improvements to code and text; added final note.

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Need help figuring out how to order/eval the numbers by Athanasius
in thread Need help figuring out how to order/eval the numbers 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.