Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ucfirst

Status
Not open for further replies.

gm199

Programmer
Aug 9, 2001
37
US
I know Perl have the ucfirst function but I can't make it work properly when the string have more than one word.

I'm using the following routine I found in this forum that is giving me another problem: is the data contains latin caracters, the very next will be upper case.
ie. polêmica becames PolêMica
How to solve this using the routine OR ucfirst?


sub first($) {
$str = $_[0];
$str =~ s/(\b)(\w)/\U\2/g;
return $str;
}
 
its not clever, its not necessarily good, but it works.

Code:
$str = "just another perl hacker";

print ustr($str);

sub ustr{
   @str = split(' ', shift);
   foreach(@str){$u .= ucfirst($_)." ";}
   chop $u; return $u;
}
 
Worked fine.
I just added

$str = lc($str);

before call the sub to make sure Ill get only the first letter in UPPER CASE

Many thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top