Just for the sake of showing another solution (even though I'm not doing any 
multi-line matching), how about:

##############################

use strict;
use warnings;
open(INFILE,"myfile.txt") || die "Couldn't open myfile.txt for writing!\n";
while(<INFILE>){
   my %person;
   $person{name} = $_;
   $person{city} = <INFILE>;
   $person{state} = <INFILE>;
   $person{address} = <INFILE>;
   $person{age} = <INFILE>;
   #do whatever you want with your lines here
}

##############################

This gets you the whole record in a hash that goes out of scope after each record so 
that you don't have to slurp the file, but you have the flexibility to do whatever you 
want with the data.  You can replace the city and state lines with just <INFILE>; on 
its own line if you don't need the data for anything.  Of course I'm assuming the file 
is in order, but I figured that was implied by the "three consecutive lines" part of 
your question.



-----Original Message-----
From: Jose Malacara [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 14, 2004 5:23 PM
To: [EMAIL PROTECTED]
Subject: multiline matching


Can someone explain to me how to do multiline matching? I am trying to extract three 
consecutive lines from a datafile containing multiple records like this:

Name: Bob
City: Austin
State: Texas
Address: 123 Whatever
Age: 46 

Name: Jose
City: Denver
State: Colorado
Address: 118 Mystreet
Age: 28 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to