remluvr:

And the result I got when I run it on previous data is wrong, since it looks like it runs just over every entry of beast-n and repeats the calculations on it.

Yes, that's clearly what you're doing:

while (<INPUTB>) { my ($u, $superclass,$rel,$v) = (split)[0,1,2,3]; my $conteggio=&calcolo($u,$v); print OUT "$u"."\t".$rel."\t".$v."\t".$conteggio."\n"; }

Perhaps it would be better to read lines in groups, so you have similar records at the same time, then you can pass the smaller set of records into your calculation routine. Something like (untested):

my $cur_superclass; my @records; while (<INPUTB>) { my ($u, $superclass,$rel,$v) = (split)[0,1,2,3]; $cur_superclass = $superclass if !defined($cur_superclass); if ($cur_superlclass ne $superclass) { my $conteggio=calcolo(\@records); print OUT "$u"."\t".$rel."\t".$v."\t".$conteggio."\n"; @records = (); } push @records, [ $u, $superclass, $rel, $v ]; $cur_superclass = $superclass; }

This will, of course, complicate calcolo() a bit, as you'll have to iterate over the records to find what you're looking for. But at least it will ensure that you're processing all the related records at once, rather than repeating the calculation over and over:

sub calcolo { my $rRecs = shift; # Number of records my $found_recs = @{$rRecs}; for my $rRec (@$rRecs) { # compute partial values my ($u, $superclass, $rel, $v) = @$rRec; .... } # combine partials return $partials / $found_recs; # or some such... }

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Cycle, iterations and statistical measure got completely wrong by roboticus
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.