warn "..." unless $type;

which are both more efficient and clearer.

However, you then go on to use $type as a hash key in

$by_type{$from}{$type} += $tmp_c;