#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |