Beginner wrote:
> Hi All,

Hello,

> I have a list of names all in uppercase that I would like to 
> capitaIise. I can't help but think that map could make short work of 
> this loop but I am not sure how. Is it possible to use map here 
> instead of a for loop? I can see there are going to be issues with 
> double-barrelled names but I'll cross that bridge later.
> 
> 
> Thanx,
> Dp,.
> 
> while (<DATA>) {
> 
>  my @words = split(/\s+/,$_);
>  my $str;
>  foreach my $w (@words) {
>       my $s = lc($w);
>       $s = ucfirst($s);
>       $str .= $s.' ';
>  }
>  print "STR=$str\n";
> }
> 
> __DATA__ 
> SOME NAME
> SOMEONE WITH FOUR NAMES
> ONE WITH THREE
> A-HYPENED NAME


Try it like this:

while ( <DATA> ) {
    s/([[:alpha:]]+)/\L\u$1/g;
    print "STR=$_";
    }

__DATA__
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to