in reply to Correct case

This should do what you want:

my $upcased = join(" ", map(ucfirst($_), split(/\s+/, $str)));
Note that I didn't test this and that it will replace multiple spaces between words with a single one. Basically, the ucfirst function is applied to each word in the list obtained by splitting the original string. After that, that list is join together again.

Hope this helps, -gjb-

Replies are listed 'Best First'.
Re: Re: Correct case
by Zaxo (Archbishop) on Jan 13, 2003 at 16:34 UTC

    ++gjb. Here is a variation which better preserves the original: my $upcased = join '', map { ucfirst } split /(\s+)/, $str; The parens in split's pattern make the seperating string be included in the resulting list. The ucfirst function has no effect on the captured whitespace.

    After Compline,
    Zaxo

Re: Re: Correct case
by dragonchild (Archbishop) on Jan 13, 2003 at 16:35 UTC
    $name =~ s/(?:\s|^)(\w)/uc($1)/eg;
    Faster and easier to read. (Shorter without obfuscation means less for the human to parse.)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.