Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Pseudocode for table data

by clueless newbie (Curate)
on Mar 17, 2020 at 21:19 UTC ( [id://11114404] : note . print w/replies, xml ) Need Help??


in reply to Pseudocode for table data

Just for amusement:

#!/usr/bin/env perl # 11114393 use Params::Validate(':all'); use 5.01800; use warnings; local $/; say <DATA>=~ s{^(.+)$}{with_mean($1)}gemr; exit; sub with_mean { my ($line)=validate_pos(@_,{ type=>SCALAR }); return $line if ($line =~ m{^GeneName}); my ($count,$sum); ()=$line=~ m{ (\d+)(?{ $count++; $sum+=$1; })}g; return "$line: @{[($sum+0.0)/$count]}"; }; __END__ GeneName E1 E2 E3 E4 ATA1 12 44 45 33 OSA2 100 79 85 83 DUA5 66 65 64 67 AXANT 4 4 6 2

gives

GeneName E1 E2 E3 E4 ATA1 12 44 45 33: 33.5 OSA2 100 79 85 83: 86.75 DUA5 66 65 64 67: 65.5 AXANT 4 4 6 2: 4