in reply to Parsing a Simple Log File
If you work with records as units rather than with lines things get a little easier:
use warnings; use strict; my @records; local $/ = "\n\n"; while (<DATA>) { my ($title, $row) = /TEST\s+\w+\W+(\w+)\D+(\d+)/; next unless defined $row; push @records, [$title, $row]; } print "$_->[0] -> $_->[1]\n" for @records; __DATA__ data per sample
Prints:
CUSTOMERPHONE -> 1300 CUSTOMERORDER -> 0 CUSTOMERCARE -> 530
Note that @records is used to preserve the order of the data in the source. The reversion to using a hash should be simple and obvious.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing a Simple Log File
by bichonfrise74 (Vicar) on Nov 05, 2008 at 00:39 UTC | |
|
Re^2: Parsing a Simple Log File
by gone2015 (Deacon) on Nov 05, 2008 at 13:16 UTC |