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..." :)