Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Uppercase First Letter w/exceptions

by Storm (Novice)
on Aug 09, 2000 at 22:55 UTC ( [id://27143]=perlquestion: print w/replies, xml ) Need Help??

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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found