in reply to compare and sum hash from array
Update : as this looks like homework, change my solution to be more cryptic, and from which I'm quite sure the OP will be able to learn from :
As you say in your title, you must use a hash:
m!([\S]+)\t(\d+)(?{$hash{$1} +=$2})! while (<DATA>); print "$_ -> $hash{$_}\n" foreach (keys %hash); __DATA__ 192.168.1 23 192.168.1 14 192.168.4 8 192.168.3 13 192.168.3 12
However, you question looks like a homework. I would be better if you provided your work so that we give you direction or better code if needed.
PS : anyone interested into a obfuscated context on this request ?
|
|---|