Perl Newby has asked for the wisdom of the Perl Monks concerning the following question:

I am in the process of converting text files into an HTML format. The files are sent in a predefined format from the company that is supplying the information. Below is an example of a piece of the text file.
LINESCORE 16|Minnesota Timberwolves|26|26|16|19|87 10|Houston Rockets|35|30|30|19|114 OFFICIALS RONNIE NUNN|RON OLESIAK|PHIL ROBINSON| ATTENDANCE 16285 TIME 2:07
What I need help with is the "Officials". I do not want them to appear in all caps. Does anyone know a way to get the officials to appear in this format "Ronnie Dunn"?

Replies are listed 'Best First'.
Re: Converting letters from uppercase to lowercase.
by runrig (Abbot) on Jun 04, 2001 at 23:38 UTC
    What about 'McDonald'? Try Lingua::EN::NameCase. Nothing like this can be 100% perfect, but it does a decent job.
Re: Converting letters from uppercase to lowercase.
by Kanji (Parson) on Jun 04, 2001 at 23:33 UTC

    Take a look at the ucfirst and lc functions.

    $name = "RONNIE NUNN"; $name = ucfirst( lc( $name ) );

    buuuuhhh... (aka 'update'). Not thinking, sorry ... that only handles the first character. Try something like ...

    $name = "RONNIE NUNN"; $name =~ s/(\S+)/\u\L$1/g;

        --k.


Re: Converting letters from uppercase to lowercase.
by lhoward (Vicar) on Jun 04, 2001 at 23:40 UTC
    Check out Lingua::EN::NameCase. Properly capatalizing names is an imperfect art at best, but this module does a good job of it.
Re: Converting letters from uppercase to lowercase.
by wog (Curate) on Jun 04, 2001 at 23:34 UTC
    sub namecase { my(@names) = @_; s/(\w+)/\L\u$1/g for @names; return @names; } # For example: print join "\n" => namecase('RONNIE NUNN', 'RON OLESIAK'); print "\n";

    That works because the \L says "all lowercase", and the \u says "next letter uppercase".

Re: Converting letters from uppercase to lowercase.
by bikeNomad (Priest) on Jun 04, 2001 at 23:37 UTC
    You can use a regex:

    my $line = 'RONNIE NUNN|RON OLESIAK|PHIL ROBINSON'; $line =~ s/\b(.)(\w*)\b/\u$1\L$2/g;
Re: Converting letters from uppercase to lowercase.
by fs (Monk) on Jun 04, 2001 at 23:31 UTC
    Check out the "ucfirst" function.
Re: Converting letters from uppercase to lowercase.
by Daddio (Chaplain) on Jun 05, 2001 at 04:47 UTC

    Another way is to get fancy with map and split.

    This assumes that the data is in $_, like from a (<FH>) read...

    print join "\n", map{ join " ",map{ ucfirst(lc) } split / / } split /\|/;
    Or assign to an array:
    @array = map{ join " ",map{ ucfirst(lc) } split / / } split /\|/;

    Sorry if it is a little obfuscated, but I think I still have a little of it in my blood from the weekend ;)

    This is really nothing more than mapping the ucfirst and lc onto the split of a split. I found I had to do it this way to avoid the dreaded implicit split to @_ depricated message.

    D a d d i o