CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [ozi] Parsing Text File: Edit Log



FishMonger
Veteran / Moderator

Dec 15, 2008, 9:24 AM


Views: 1995
Re: [ozi] Parsing Text File

I'm not sure how much of that data you want to extract, but see if this is close.


Code
#!/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)


Edit Log:
Post edited by FishMonger (Veteran) on Dec 15, 2008, 9:26 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives