in reply to Upper case first letter of each _ delimited word

Useful. How about wrapping in a sub and letting the caller specify the delim?
sub ucwords { join $_[1], map ucfirst lc, split /\Q$_[1]\E/, $_[0], -1; }
Updated to fix the bugs tilly mentions below.

To be called like:

print ucwords("BATCH_USER_INFO", "_");
There may be a faster way, and if there is I'm sure someone'll point it out. :)

Replies are listed 'Best First'.
Re (tilly) 2: Upper case first letter of each _ delimited word
by tilly (Archbishop) on Dec 05, 2000 at 03:25 UTC
    Tsk tsk.
    print ucwords("hello_world_", "_"); print ucwords("hello*world", "*");
    You need to specify the third argument to split and handle meta characters more carefully...
Re: Re: Upper case first letter of each _ delimited word
by japhy (Canon) on Dec 05, 2000 at 02:44 UTC
      That's a nice solution, but but I think it is missing a couple features: it doesn't catch the first word in the string; it doesn't lowercase the rest of each word; and it doesn't allow variable-width delimiters. Here's a modified version that addresses those issues.
      sub ucwords { my($new, $delim) = @_; $new =~ s/($delim|^)(.*?)(?=$delim|$)/$1\u\L$2/sg; $new; }
      To match an entire word, from one delimiter to the next, I used a non-greedy match and a positive lookahead.
      That's slick but it doesn't quite work:
      print ucwords("BATCH_USER_INFO", "_"), "\n"; print ucwords("batch_user_info", "_"), "\n";
      produces
      BATCH_USER_INFO batch_User_Info
      In the first case you don't ever lower-case the string; in the second case you don't look for "word" at the beginning of the string, before the delim.