use strict; use warnings; use Text::ASCIITable; use open qw(:std :utf8); my %hash; my $tb = Text::ASCIITable->new(); $tb->setCols( 'WordF1', 'WordF2', 'Difference' ); while (<>) { next if $. < 3; push @{ $hash{$1} }, $2 while /\|\s+(\w+)\s+\|\s+([.\d]+)/g; } for my $word ( keys %hash ) { if ( @{ $hash{$word} } == 2 ) { $hash{$word} = $hash{$word}->[0] - $hash{$word}->[1]; } else { delete $hash{$word}; } } for my $word ( sort { $hash{$b} <=> $hash{$a} } keys %hash ) { $tb->addRow( $word, $word, sprintf( '%0.05f', $hash{$word} ) ); } print $tb; #### .--------------------------------------. | WordF1 | WordF2 | Difference | +------------+------------+------------+ | politici | politici | 0.01940 | | referendum | referendum | 0.01726 | | verità | verità | 0.01454 | | scandalo | scandalo | 0.00978 | | consenso | consenso | 0.00887 | | vergogna | vergogna | 0.00592 | '------------+------------+------------' #### use strict; use warnings; use Text::ASCIITable; use open qw(:std :utf8); my %hash; my $tb = Text::ASCIITable->new(); $tb->setCols( 'WordF1', 'WordF2', 'Difference' ); while (<>) { my ( $word, $val ) = (split)[ 0, -1 ]; push @{ $hash{$word} }, $val; } for my $word ( keys %hash ) { if ( @{ $hash{$word} } == 2 ) { $hash{$word} = $hash{$word}->[0] - $hash{$word}->[1]; } else { delete $hash{$word}; } } for my $word ( sort { $hash{$b} <=> $hash{$a} } keys %hash ) { $tb->addRow( $word, $word, sprintf( '%0.06f', $hash{$word} ) ); } print $tb; #### .----------------------------------------------------. | WordF1 | WordF2 | Difference | +-------------------+-------------------+------------+ | consensi | consensi | 0.000626 | | disonesti | disonesti | 0.000507 | | antidemocratico | antidemocratico | 0.000102 | | antidemocraticità | antidemocraticità | 0.000029 | | antidemocratica | antidemocratica | -0.000014 | | antidemocratici | antidemocratici | -0.000017 | | consensuali | consensuali | -0.000040 | | antidemocratiche | antidemocratiche | -0.000130 | | consensuale | consensuale | -0.000230 | | consenso | consenso | -0.008922 | '-------------------+-------------------+------------'