in reply to Capitalize the 1st letter of each word

If you hit the Library, under Perl Functions, Alphabetical, you'll find ucfirst() and lcfirst(), which will upper- or lower-case (respectively) the first character of a given word. So you could do something along the lines of:

my @array = qw( foo bar foobar barfoo 1 2 3 ); foreach my $i (0 .. $#array) { $array[$i] = ucfirst($array[$i]); }

I suspect a regex in this case is actually overkill.... HTH....

Replies are listed 'Best First'.
Re: Re: Capitalize the 1st letter of each word
by mcogan1966 (Monk) on Jan 15, 2004 at 20:02 UTC
    Or even faster:
    foreach (@array) { ucfirst($_); }
    In this case, $_ will point to the actual element in the array.

      Unfortunately, that doesn't work

      my @words = qw[ the quick brown fox ]; foreach (@words) { ucfirst($_); }; Useless use of ucfirst in void context at ...

      It would have to be

      foreach (@words) { $_ = ucfirst($_); }

      Or, more simple

      $_ = ucfirst for @words; print for @words; The Quick Brown Fox

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      Timing (and a little luck) are everything!