Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?  Re^3: How best to
strip text from a file?  by Corion (Pope) on Nov 05, 2012 at
14:49 UTC ( #1002335=note: print w/ replies, xml ) Need Help??
in reply to Re^2: How best to strip text from a file? in thread
How best to strip text from a file?  Where does one record end
and the next record start?  If FOO: marks the start of a new
record, I wouldn't try to collect everything with one regular
expression but go through the input line by line, and either set
up a new field name into which to collect, or flush the current
set of data once a new starting marker has been found:  use
strict; use Data::Dumper; my %record; sub flush { print Dumper
\%record; %record = (); }; my $current; while (<DATA>) { if(
/^(FOO):(.*)/ ) { flush() if keys %record; $current = $1;
$record{ $current }.= $2; } elsif( /^([A-Z]+):(.*)/ ) { $current
= $1; $record{ $current }.= $2; } else { $record{ $current }.=
$_; }; }; flush() if ke