On Monday, May 6, 2002, at 05:45 , Marc M Dawson wrote:
> 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.
why a 'split'????
If you only want the 'full user name' why not simple:
while ( <INFO1> ) {
/^\s*\d+\s*([\w\s]+)\</;
my $person = $1;
print "found :$person\n";
push (@info, $person);
}
or the more complex if you want to save them all
while ( <INFO1> ) {
/^\s*(\d+)\s*([\w\s]+)\<(\S+)\>/; # more round parens more things
my $num = $1;
my $person = $2;
my $email = $3;
print "found :$person\n";
$info{$num} = [$person, $email];
}
hence to unpack that %info with
while ( my ($key, $val) = each %info ) {
print "At $key we have\n";
print "\t$_\n" for (@$val) ;
}
the trick is to find the pattern in the data.....
It is all a matter of 'where is waldo'?????
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]