Here's one way with a regex:

open(INFILE,"myfile.txt") || die "Could not open myfile.txt!\n";
while(<INFILE>){
   $_ =~ /^(\d{6})\s+(\w+\s*\w*)\s+(\w+)\s+(<.+\@.+>)\s*$/ || die "Improper
format";
   $index = $1;
   $firstmaybemiddle = $2;
   $last = $3;
   $smtpaddr = $4;
}

Now I haven't had a chance to test this out, so I might have the escapes
wrong somewhere or something, but that's the gist.  By using \s*\w* it
should only capture the middle name if it exists.

-----Original Message-----
From: Marc M Dawson
To: [EMAIL PROTECTED]
Sent: 5/6/02 5:45 PM
Subject: Ok- real dumb question

I am supposed to parse a text file such as this-
781457  Hartanto Victor Setiawan <[EMAIL PROTECTED]>
777557  Hatfield Benjamin <[EMAIL PROTECTED]>
779777  Henry James <[EMAIL PROTECTED]>
777947  Hergert Michael William <[EMAIL PROTECTED]>
778097  Iverson Jennifer Marsee <[EMAIL PROTECTED]>

As you can see... some people have middle names and some dont... how
would I
go about parsing this text file and putting each into it own seperate
entity, except if there is a middle name, in which case I want it to be
joint first and middle.  I realize that I am supposed to use some kind
of
split function, however I am unsure how to use it fully, and the
prfessor
didnt go over it too much.
Thanks for any help!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to