A one liner to produce Title Case (i.e. Set The First Letter Of Each Word Of A Phrase To Upper-case). This gives two examples:

  1. To title case a phrase specified in the same one liner
  2. To title case a whole file.
  3. Note:
    I set the split command to assume that words are separated by whitespace, commas, or dashes--but there's sure to be an exception,you see. This can be modified, though.

    My system wants me to use double quotes when I do a perl -e. This is why I use a qq at the end.

    update:As danger says, there is an existing FAQ on this at How do I capitalize all the words on one line?. I didn't turn it up in my initial search (I tried title case, upper case, etc.)

    thanks, danger and arhuman

Phrase in one-liner
perl -e "$_='ZENO WAS HERE';@ph=map {ucfirst(lc)} split(/[\s.,-]+/);pr +int qq(@ph)"
Phrase in separate file
perl -p -e "@ph=map {ucfirst(lc)} split(/[\s.,-]+/);print qq(@ph)" c:\ +foo.dat

update: arhuman sent me this smart variation (it leaves a trailing space, but is shorter):

perl -e '$_="ZENO WAS HERE"; print map {ucfirst(lc)," "} split/\s+/'

In reply to Title Case One-Liner by zeno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.