Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: MySQL Alphabetical order with DBI

by schumi (Hermit)
on Nov 15, 2002 at 15:16 UTC ( #213167=note: print w/replies, xml ) Need Help??


in reply to MySQL Alphabetical order with DBI

I like UnderMine's idea, but this only works assuming that there's no double last name with a space between them in the database. If, for example, you have a weird name like "John de Clerk", then the "de"-bit would be regarded as a part of the first name.

Even worse, when someone has a name like "Sandra Meier Schenk". With Swiss people, this could very well occur, with "Sandra" being the first name, "Meier" being the woman's maiden, and "Schenk" the last name of her husband. According to Swiss law, this is perfectly possible and these days even quite frequent. (I won't go into the possible weird situations to which that might lead, let your own imagination run wild.... :-)

Now, I don't know what you intend to do with the data once you've extracted it. If it's just about sorting the stuff, then this might do.

If, however, you want to do something more with the data, even if it's at a later stage, then the only way to go is to re-structure your database. This helps you with your immediate problem, and also puts your data in a form which, should a similar need turn up again, makes the problem much easier. To achieve this, apart from doing it by hand (which is hardly ever an option, unless you only have five entries), the afore-mentioned Lingua::EN::NameParse is probably best.

--cs

There are nights when the wolves are silent and only the moon howls. - George Carlin

Replies are listed 'Best First'.
Re: Re: MySQL Alphabetical order with DBI
by seattlejohn (Deacon) on Nov 15, 2002 at 16:38 UTC
    (This may be a bit tangential to the specific question, but I don't think it's entirely off-topic...)

    I can attest to having encountered the multiple-last-name problem firsthand. Because my parents were uncreative (just kidding, mom & dad :-), they decided to give me the same first and middle names as my father, which were the same as his father's, and his father's... so my legal name actually has an "IV" (Roman numeral 4) suffix on it. Every now and then I'll do something like withdraw money from an ATM and have it display something like "Thank you, Mr. IV".

    Chinese names present an altogether different problem, because in Chinese the last name comes first. This means that Mao Zedong, for example, is (well, was) Mr. Mao, not Mr. Zedong or Mr. Dong.

    What's my point here? That name parsing is another of those tasks in which the naive algorithm (split on spaces) can miss a lot of subtle cases. If the data set is not trivial and you want to get it right -- which is a laudable goal, as many people get annoyed when their names are mangled -- using something like Lingua::EN::NameParse is probably smart. (It won't handle Chinese names as far I can tell, but then it does live under Lingua::EN...)

            $perlmonks{seattlejohn} = 'John Clyman';

Re: Re: MySQL Alphabetical order with DBI
by UnderMine (Friar) on Nov 15, 2002 at 16:12 UTC
    I think it should work in all the above cases as it is the equivalent of s/^.*?\s(.*)$/$1/ but it will fail on multiple firstnames or titles.

    Dr. John Smith
    A N Other

    You normally want to store :- Title, Firstname, Surname, Other Names/Initials and any other data. I have even used a seperator in the name like : if I can not change the database structure for some reason.

    Hope this helps

    UnderMine

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-01-16 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?