in reply to Help Parsing a Text File
You have to love data files with inconsistent record separators. If you had "\n\n" ie a blank line as the rec sep you could just set $/ = "\n\n" to read a record at a time. You could fix the file format with this:
perl -pi.bak -e 's/--\n/\n/' inconsitent.txt
You could then just set the input record separator to two newlines and read the data in one record at a time. But you say that the -- is an important part so you need to do something like this:
my @recs; my $data = ''; while(<DATA>) { next unless $data or m/\d+\-\d+/; $data .= $_; if ( m/^(?:\n|\-\-\n)$/ ) { push @recs, $data; $data = ''; } } print "$_\n\n\n" for @recs;
so that you don't lose the -- parts.
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Help Parsing a Text File
by PrimeLord (Pilgrim) on Mar 23, 2004 at 19:51 UTC |