I altered your script so that it would just work. The biggest problem that I encountered was getting around the illegal divsion by zero such as:
$precision = $feature_found / $rank;
What I did:
$precision = eval { $feature_found ? $rank / $feature_found : 0; };
Here's the script:
#!/usr/bin/perl use strict; use autodie; use Devel::SimpleTrace; use Data::Dumper::Concise; my $input = shift @ARGV; my $input_bless = ''; my $log = '/root/Desktop/log.txt'; die $! unless open IN, '<', $input; die $! unless open OUT, '>', $log; my %matrice; while ( defined( $_ = <IN> ) ) { my ( $rank, $nome, $relaz, $entry2, $score ) = split( ' ', $_, 6 ) +; push @{ $matrice{$nome}; }, "${relaz}_$entry2,$rank,$score"; } my %HOH; while ( my ( $name, $aref ) = each %matrice ) { do { foreach my $item (@$aref) { my ( $prop, $rank, $score ) = split( /,/, $item, 4 ); $HOH{$name}{$prop} = "$rank,$score" || 0; } }; } die unless open INB, '<', $input; while ( defined( $_ = <INB> ) ) { my ( $u, $superclass, $rel, $v ) = ( split( ' ', $_, 0 ) )[ 0, 1, 2, 3 ]; my $conteggio = &calcolo( $u, $v ); print OUT "$u" . "\t" . $rel . "\t" . $v . "\t" . $conteggio; } sub calcolo { my ( $name1, $name2 ) = @_; my $first = $HOH{$name1}; my $second = $HOH{$name2}; my ( $rank_fv, $score_fv ); my $rank_v; my $count_feat_fv; my $provaprec = 0; my $proptoexamine; my $count_feat_rel; my $precision; my $rel_par; my $num = 0; my $count_feat_fu; my $apinc; my $rank2 = 0; my ( $prop, $score ); my $rank = 0; my $feature_found = 0; my $feat_finale; my $rel_to_sum; while ( my ( $name1, $aref ) = each %matrice ) { ++$count_feat_fu; $num = 0; my $feat_rel = 0; foreach my $item (@$aref) { ( $prop, $rank, $score ) = split( /,/, $item, 4 ); $feat_finale = &last_el_v( $name2, $prop ); while ( my ( $prop1, $rankscore1 ) = each %$second ) { ($rank_fv, $score_fv ) = split( /,/, $rankscore1, 3); if ( $prop1 eq $prop ) { ++$feature_found; print 'PROP:' . $prop . "\n"; print "TROVATO" . "\n"; ++$feat_rel; $rank2 = $rank_fv; print 'RANK 2:' . $rank2 . "\n"; print 'RANK 1: ' . $rank . "\n"; print 'COUNT FEAT FOUND: ' . $feature_found . "\n" +; $precision = eval { $feature_found ? $rank / $feature_found : 0; }; print 'PRECISION: ' . $precision . "\n"; $rel_par = $rank2 / ( $feat_finale + 1 ); $rel_to_sum = 1 - $rel_par; print 'FEAT FINALE: ' . $feat_finale . "\n"; print 'REL PAR: ' . $rel_par . "\n"; my $tosum = $precision * $rel_to_sum; print 'TO SUM: ' . $tosum . "\n"; $num = $num + $tosum; print 'NUM: ' . $num . "\n"; } }; } print 'RANK: ' . $rank . "\n"; $apinc = eval { $num ? $rank / $num : 0; }; print 'APINC: ' . $apinc . "\n"; return $apinc; }; } sub last_el_v { my ( $name2, $prop1 ) = @_; my $second = $HOH{$name2}; my $count_feat_fv; while ( my ( $prop1, $rankscore1 ) = each %$second ) { ++$count_feat_fv; }; return $count_feat_fv; } close IN; close INB; close OUT;

In reply to Re: Cycle, iterations and statistical measure got completely wrong by Khen1950fx
in thread Cycle, iterations and statistical measure got completely wrong by remluvr

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.