
FishMonger
Veteran
Dec 15, 2008, 9:24 AM
Views: 1197
|
|
Re: [ozi] Parsing Text File
|
|
|
I'm not sure how much of that data you want to extract, but see if this is close.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my (%data, $client, $note); my $datafile = 'filename'; open my $DATAFILE, '<', $datafile or die "can't open '$datafile' $!"; while( my $line = <$DATAFILE>) { if ( $line =~ /^\s+- Body: (.*\n)/ ) { $data{$client}{$note}{body} .= $1; while ( $line = <$DATAFILE> ) { if ( $line =~ /\s+Note (\d+):/ ) { $note = $1; last; } $data{$client}{$note}{body} .= $line; } next; } $client = $1 if $line =~ /^- Name: (.+)/; $note = $1 if $line =~ /\s+Note (\d+):/; if ( $note and $line =~ /^\s+- (\w+):\s*(.+)/ ) { $data{$client}{$note}{$1} = $2; } } print Dumper \%data;
(This post was edited by FishMonger on Dec 15, 2008, 9:26 AM)
|