#!/usr/bin/perl -ws
# read several files containing numbers and possibly also other text,
# average any set of numbers found in the same place in all the files,
# and print the result.
# numbers immediately following letters don't count.
use File::Slurp;
@ARGV or die "no input files\n";
my @data;
foreach $fh (@ARGV) {
    push @data, scalar(read_file($fh));
}
my $all;
while($data[0] =~ /(?<![a-z])\d/i) {
    my $seperator = "";
    my $value = 0;
    my $denom = 0;
    my $diff = 0;
    my $prev;
    my $decimals = 0;
    foreach(@data) {
        s/^(.*?)(?<![a-z])(-?\d+\.?\d*)//si or warn "short\n" and next;
        $diff ||= $denom && ($2 ne $prev);
        $prev = $2;
        $seperator ||= $1;
        $value += $2;
        $denom ++;
        if($2 =~ /\.(\d+)/ && $decimals < length($1)) {
            $decimals = length($1);
        }
    }
    if($d){
        $decimals += $denom < 10 ? 1 : int(log($denom)/log(10));
    }
    $all .= $seperator;
    $all .= $diff ? sprintf("%.${decimals}f", $value/$denom) : $prev;
}
$all .= $data[0];
print $all;
undef $d;
