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

Re: How to read a file and add value for same key

by Skeeve (Vicar)
on Jul 31, 2013 at 09:49 UTC ( #1047223=note: print w/ replies, xml ) Need Help??


in reply to How to read a file and add value for same key

Just for the fun of it:

$_=<>; 1 while (s/(\w)\s(\d+)(.*)(\s\1\s)(\d+)/$1." ".($2+$5).$3/e); print

Example call:

$ cat test a 1 b 3 c 5 a 2 $ ./samekey test a 3 b 3 c 5 $ cat anothertest a 1 b 3 c 5 a 2 a 3 b 3 c 5 $ ./samekey anothertest a 6 b 6 c 10

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e


Comment on Re: How to read a file and add value for same key
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047223]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-01 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (19 votes), past polls