in reply to Case Munging

What about this:
perl -i.old -pe 's/(?<![a-z])(\w)/uc $1/eg' <FILENAME>
After this runs you have all "translated" names in <FILENAME>. The old version of the file is kept as "<FILENAME>.old".
And it translates run4life to Run4Life as requested.

And in case the regex is unclear: The first part is a negative lookahead (see perldoc perlre).

Replies are listed 'Best First'.
Re^2: Case Munging
by morgon (Priest) on Apr 17, 2009 at 00:15 UTC
    It just occurs to me that you said the file holds the names in upper cases (my previous post assumed lower-case).

    So use this instead:

    perl -i.old -pe 's/(?<=[A-Z])(\w)/lc $1/eg' <FILENAME>
    And the regex contains a (this time positive) lookbehind-assertion (and not lookahead as I wrote above).

    Sorry for the confusion.

      FWIW, the following may give a slight improvement in speed, simplicity or generality (I will not bother to put it into file-processing form):
      >perl -wMstrict -le "for (@ARGV) { s{ (?<= [[:upper:]]) ([[:upper:]]+) }{\L$1}xmsg; print; } " "XYZZY" "RUN4LIFE" "RUN42LIFE CO" "GENERAL WIDGET CO., INTL" "MI-GO BRAIN CYLINDERS, IPTY." Xyzzy Run4Life Run42Life Co General Widget Co., Intl Mi-Go Brain Cylinders, Ipty.
      Supposed advantages:
      • The  ([[:upper:]]+) quantified capture grabs as much as possible of whatever is to be lower-cased (rather than capturing a character at a time);
      • The use of the  \L interpolation modifier eliminates the need for evaluation in the regex (i.e., no  //e regex modifier);
      • The use of  [[:upper:]] and  \L bring locale fully into play (I think).
      Good clarification for the archives. I'd mentally prefaced `lc <INPUT>` since that was a necessary step to get to the end state.
      Be Appropriate && Follow Your Curiosity
Re^2: Case Munging
by mikeraz (Friar) on Apr 17, 2009 at 00:20 UTC
    I like that, just the kind of thing I was fumbling towards.
    Be Appropriate && Follow Your Curiosity