Another possibility that could be adapted to fit:
use warnings;
use strict;
my $text = "I am a GIRL, a Real GIRL. A test WITH Multiple conDITions
+AND other tests.";
print map{"$_ "}
map{$_ = lc($_) unless (($_ eq uc $_) and length $_ > 1 ); $_ }
map{split ' ',$_}$text;
__END__
Prints:
i am a GIRL, a real GIRL. a test WITH multiple conditions AND other te
+sts.
Converting between upper and lower case ASCII is just flipping a bit (fast). No regex is needed here. length() is also very fast. $_ eq uc $_ should be very fast. This map,map,map stuff is slow, but speeding that up is left to the reader.
Update: Here is one possibility of many:
use warnings;
use strict;
my $text = "I am a GIRL, a Real GIRL. A test WITH Multiple conDITions
+AND other tests.";
print "".onlyAllcaps ($text);
sub onlyAllcaps
{
my $input = shift;
my @words = split ' ',$text;
foreach my $word (@words)
{
$word = lc($word) unless (($word eq uc $word) and length $word>
+1 )
}
my $output = join " ",@words,"\n";
return $output;
}
__END__
Prints:
i am a GIRL, a real GIRL. a test WITH multiple conditions AND other te
+sts.
|