Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Title Case One-Liner

by danger (Priest)
on Feb 09, 2001 at 22:00 UTC ( [id://57423]=note: print w/replies, xml ) Need Help??


in reply to Title Case One-Liner

There are also variations of one of this faq's answers which are a little shorter and also adjustable:

perl -le '$_="ZENO WAS HERE";s/([^\s.,-]+)/\u\L$1/g;print' perl -le '$_="DANGER was hERe too";s/(\S+)/\u\L$1/g;print'

Replies are listed 'Best First'.
Re: Re: Title Case One-Liner
by japhy (Canon) on Feb 10, 2001 at 00:46 UTC
    I suggest s/([^\s\w]*)(\S+)/$1\u\L$2/g; instead. It treats things like q{"not a question" folks} (which becomes q{"Not A Question" Folks}).

    japhy -- Perl and Regex Hacker
      The trick there is making sure the first character is a word character. Here's a shorter version of the same thing: s/(\w\S*)/\u\L$1/g;
      Nice, but both this and chipmunk's can't handle "just,another,list,of,words" (ie. punctuation without spaces)... why not just:
      s/(\w+)/\u\L$1/g;
      Update: eating self-served humble pie, never mind, this can't deal with "i promise i won't shouldn't can't reply without thinking..." :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 20:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found