in reply to Can't seem to match from one varibale to next one.
This bit:
while ( $line = <> )
... is only reading a single line at a time. Adjusting your regular expression won't make a difference because the variable that you're matching it against is only ever one line!
You need to loop through lines, not doing anything except accumulating them into a variable; and only when you hit the start of a new record, processing that accumulated variable (then resetting it).
Here's a somewhat simplified example:
use Data::Dumper; sub process_record { my $record = join q[], @{+shift}; warn "Malformed record: $record" unless $record =~ /^ \[ (.+?) \] \s+ \[ (.+?) \] \s+ (.+) $/xs +; local $Data::Dumper::Terse = 1; print "Got record ", Dumper +{ datetime => $1, status => $2, info => $3, }; } my $current_record; while (<DATA>) { # we have hit a new record if (/^ \[ \d{4}-\d{2}-\d{2} /x) { process_record($current_record) if $current_record; $current_record = []; # start a new record } push @$current_record, $_; } # don't forget to process the final record process_record($current_record) if $current_record; __DATA__ [2012-09-14 16:55:22,498] [ACTIVE] INFO - this is a single line [2012-09-14 16:55:22,498] [ACTIVE] INFO - this is a multi line record [2012-09-14 16:55:22,500] [ACTIVE] INFO - this is another single line [2012-09-14 16:55:22,500] [ACTIVE] INFO - this is yet single line [2012-09-14 16:55:22,500] [ACTIVE] INFO - this one is on two lines [2012-09-14 16:55:22,500] [ACTIVE] INFO - one last record
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't seem to match from one varibale to next one.
by Ben328 (Novice) on Sep 16, 2012 at 19:24 UTC | |
by kcott (Archbishop) on Sep 17, 2012 at 06:35 UTC | |
by Ben328 (Novice) on Sep 19, 2012 at 22:39 UTC | |
by tobyink (Canon) on Sep 17, 2012 at 08:54 UTC |