in reply to Parsing a text file
Hope this was useful?#!/usr/bin/perl $file = 'msgcount.txt'; open (LOG, $file); my %records; # creat a hash while (<LOG>) { # each line is parsed by this regular expression: if (/^\S+ (\S+) (\d+)/) { # and the value for the name, which is now in $1 # is increased by the number in $2 $records{$1} += $2; } } # then we go through all keys (the names) # in our %record hash for (keys %records) { # and print out their sum: print "$_: $records{$_}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing a text file
by nimajneb (Initiate) on Apr 16, 2008 at 14:38 UTC |