Beginner wrote:
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-barrelle
On 2007/04/04, at 18:12, Randal L. Schwartz wrote:
"Igor" == Igor Sutton Lopes <[EMAIL PROTECTED]> writes:
Igor> my $str = join( " ", map { s/\B(\w+)/\L\1/; $_ } split( /
\s+/, $_ ) );
It's bad style to modify $_ in a map, because that also modifies
the incoming
data. The simplest
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 issu
> "Igor" == Igor Sutton Lopes <[EMAIL PROTECTED]> writes:
Igor> my $str = join( " ", map { s/\B(\w+)/\L\1/; $_ } split( /\s+/, $_ )
);
It's bad style to modify $_ in a map, because that also modifies the incoming
data. The simplest workaround is adding local:
@out = map { local $_ = $
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 issu
my $str = join " ", map { ucfirst lc } @words;
should do what your for loop is doing.
-Jason
On 4/4/07, Beginner <[EMAIL PROTECTED]> wrote:
Hi All,
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
On 2007/04/04, at 16:28, Beginner wrote:
while () {
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
Hi All,
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 bu