William Black wrote:
> Hello,
>
> I'm reading from a file. I'm trying to read in five lines at a time
> where each line has a newline and then process the lines into
> separare variables. For example,
>
> Input File
> -------------
> Stevens,
> Craig A Triangle Family Care PA
> 106-A Ridgeview Dr
> Cary, NC
> View Profile & Phone | Appointment Services 0.4
> Once the lines are read in, I want to store 'Stevens' into a Lname
> variable, 'Graig' in a Fname variable, 'A Triangle Family Care PA'
> into BusName variable, '106-A Ridgeview Dr' into a Address variable,
> 'Cary' into a City variable, and 'NC' into a state variable. Could
> someone point me in the right direction?
>
> regards,
Use Tie::File:
use strict;
use warnings;
use Tie::File;
my @f;
my $fname = shift;
tie @f, 'Tie::File', $fname or die "Can't tie file $fname: $^E";
for (my $i = 0; $i < @f; $i += 5)
{
my ($lname, $fname, $busName, $address, $city, $state);
$f[$i] =~ /^([a-zA-Z]+),/;
$lname = $1;
$f[$i+1] =~ /^([a-zA-Z]+)\s(.*)$/;
$fname = $1;
$busName = $2;
chomp($address = $f[$i+2]);
($city, $state) = split /,/, $f[$i+3];
$state =~ s/\s+//g;
}
untie @f;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>