my $sum = 0; $sum += ($weights[$_]||0) * ($digits[$_]||0) for 0 .. @#weights;