The following code transforms the first table into the second. It might be easier, though, to skip the creation of the first table and do the calculations right when processing the two text files.
#!/usr/bin/perl use warnings; use strict; use Text::Table; binmode DATA, 'utf8'; binmode STDOUT, 'utf8'; <DATA> for 1,2; # Throw away the header and the horizontal line. my %hash; while (<DATA>) { my ($w1, $p1, $w2, $p2) = (split /\|/)[1 .. 4]; last unless $w2; s/^\s+|\s+$//g for $w1, $w2; $hash{$w1}{1} = $p1; $hash{$w2}{2} = $p2; } my $table = 'Text::Table'->new(\'|', 'word', \'|', 'difference', \'|') +; for my $word (keys %hash) { my $detail = $hash{$word}; if (exists $detail->{1} and exists $detail->{2}) { $table->add($word, $detail->{1} - $detail->{2}); } } print $table->title, $table->rule('-', '+'), $table->body; __DATA__ | wordF1 | percentageF1 | wordF2 | percentageF2 | |------------+--------------+--------------+--------------| | politici | 0.0489 | politici | 0.0295 | | referendum | 0.0238 | consenso | 0.0126 | | verità | 0.0198 | referendum | 0.00654 | | scandalo | 0.0112 | verità | 0.00526 | | vergogna | 0.00723 | tradizionali | 0.00343 | | corrotto | 0.00439 | tradizione | 0.00266 | | scandali | 0.00394 | tradizioni | 0.00234 | | consenso | 0.00373 | tradizionale | 0.0022 | | corrotti | 0.00332 | scandalo | 0.00142 | | propaganda | 0.0027 | vergogna | 0.00131 | |------------+--------------+--------------+--------------|
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re: Aligning text and then perfom calculations by choroba
in thread Aligning text and then perfom calculations by epimenidecretese

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.