On Wednesday, Jul 23, 2003, at 09:58 US/Pacific, Sara wrote:
$TS = "THIS INPUT IS IN ALL CAPS";
$TS_cont = lc $TS;
$TS now prints out "this input is in all caps"
What If I want first letter in caps for every word in string? which should be "This Input Is In All Caps"
a way of solving this would be
#!/usr/bin/perl -w use strict; my($TS,$TS_cont); $TS = "THIS INPUT IS IN ALL CAPS"; ($TS_cont = $TS) =~ s/(\w)(\w+)/$1 . lc($2)/ge; print "#------\n\$TS_cont now prints out:\n $TS_cont\nwas\n $TS\n"
which generates: #------ $TS_cont now prints out: This Input Is In All Caps was THIS INPUT IS IN ALL CAPS
the Trick Part is the 'regular expression' that walks the string and expands it with the
$1 . lc($2)
Since, well, we want the first Letter to 'remain' as it was. but everything afterwards to be lower cased.
IF on the other hand you wanted to make sure that the term was upper cased then you would want say
uc($1) . lc($2)
and if you were seriously deformed and want to do it drieuxishly you might try:
$TS = "Brain Wave Sucking alien beast creatures from planet zarkon"; ($TS_cont = $TS) =~ s/(\w)(\w+)\s*/uc($1) . lc($2)/ge; print "#------\n\$TS_cont now prints out:\n $TS_cont\nwas\n $TS\n"
which generates:
#------ $TS_cont now prints out: BrainWaveSuckingAlienBeastCreaturesFromPlanetZarkon was Brain Wave Sucking alien beast creatures from planet zarkon
since as you will note, we added in the '\s*' to grab any 'white spaces' - but since we did not put them back in the 'expression' we concatenate all the words together.
HTH.
ciao drieux
---
hum... did I just fail the turing test?
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]