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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case sensitive help

Status
Not open for further replies.

MaxGeek

Technical User
Jan 8, 2004
52
US
I want to change a variable $name with the value of first.last (john.doe) to First.Last (John.Doe).

Like the format for the variable will always have a "." between the first and last name. I want to make the first letter of the first and last name are a capitol.

So I though I would split $name at the "." by doing
@split_email = split(".", $name");

But I forgot how I would set the first part of the name and last part of the name as individual variables so I can make the first letter of each upper case and then put them back together.

Can someone help me?



 
my $full_name = "donald duck";
$full_name =~ tr/A-Z/a-z/;
$full_name =~ s/\b(.)/\u$1/g;

# Output = Donald Duck

M. Brooks
X Concepts LLC
 
Sticking with your split you could also do:
Code:
@split_email = split(".", $name");
print ucfirst($split_email[0]).".".ucfirst($split_email[1])."\n";
[code]

The ucfirst() function converst the first character for the string to upper case.
Derek
 
Be careful with your split statement. Remember that the first argument split() takes is a regexp, so you have to escape the dot to stop it matching 'any character'.

Oh, and don't use double quotes for it either, unless you know why you're doing it.

Code:
@split_email = split('\.', $name");
 
Sigh, tested it twice to confirm I needed to escape the dot and then forgot to enter it that way in my post. Must have been having a bad night. Thanks. [blush]
Derek
 
Thanx for all the help, i haven't had a chance to try it yet, but I'll let you know how it goes.

 
I ended up using MrBrooks method and it worked great. Thanx for all your help everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top