Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Parsing Names in a Text File

by enoch (Chaplain)
on Jun 15, 2001 at 18:35 UTC ( [id://88804]=note: print w/replies, xml ) Need Help??


in reply to Parsing Names in a Text File

I would pass on using a regex for this one.
while(<FILE>) { @line = split '|'; # split line $firstLetter = substr $line[1], 0, 1; #grab first letter $lastName = (split(' ', $line[1]))[1]; #split the name entry on wh +itespace and grab the last name portion $name = $firstLetter . ". " . $lastName; #concatenate with period +after first letter }
Jeremy

Replies are listed 'Best First'.
Re: Re: Parsing Names in a Text File
by Anonymous Monk on Jun 15, 2001 at 20:41 UTC
    I'd recommend taking a slight variant on this in order to handle the middle name problem:
    while(<FILE>) { my @line = split '|'; # split line #so far as above apart from my declaration #now split on whitespace my @names = split ' ',$line[1]; #same idiom for getting the first letter my $firstletter = substr ($names[0],0,1); #then get the last item in the name array my $lastname = $names[-1]; #now do whatever you want to do with the letter and lastname }
    Of course this assumes that all the names are in a givenname middlenames familyname format.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://88804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-20 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found