Storm has asked for the wisdom of the Perl Monks concerning the following question:

Would anyone know how to work with these names to
convert it to Caps where needed.

ST. JOHN
STEVEN MILLER
O'REILY #f.e. O'REILY to O'Reily

I know I can use s/(\w+)/\u\L$1/g; for the first 2, but
what about the O'REILY?

One of those days :) Thanks ahead of time...

Storm

Replies are listed 'Best First'.
RE: Uppercase First Letter w/exceptions
by merlyn (Sage) on Aug 09, 2000 at 23:11 UTC
    There isn't any "rule" way to do this. For example, some people prefer MacArthur and some prefer Macarthur, so you'd need to go back to the sources to figure out the proper presentation.

    Having said that, your substitution does indeed make O'REILY into O'Reily. Is that what you want, or not?

    -- Randal L. Schwartz, Perl hacker

Perhaps this?
by gryng (Hermit) on Aug 09, 2000 at 23:01 UTC
    Perhaps this would work? (warning un-tested):

    s/([\w']+)/\u\L$1/g;

    The idea is to put any characters that will cause an uppercase inside the brackets along with the \w (you could put in underscores and dashes too, if appropriate).

    G'Luck
    Gryn

Re: Uppercase First Letter w/exceptions
by lhoward (Vicar) on Aug 09, 2000 at 23:13 UTC
    You probably also want to account for names w/ mixed case but no non-letter delimiters in-between such as McDonald and MacFrugal.
Re: Uppercase First Letter w/exceptions
by TheOtherGuy (Sexton) on Aug 09, 2000 at 23:12 UTC
    Maybe I am totally misunderstanding the question, but whay are you not using the uc() or lc() functions?