Google Answers Logo
View Question
 
Q: How to capitalize the first letter of each word in PERL ( No Answer,   2 Comments )
Question  
Subject: How to capitalize the first letter of each word in PERL
Category: Computers > Programming
Asked by: yt_nitram-ga
List Price: $5.00
Posted: 09 Jul 2005 12:17 PDT
Expires: 15 Jul 2005 13:31 PDT
Question ID: 541585
I have a search engine script written in Perl/CGI, and most of the
users input their query "all lowercase".  I want to know the line(s)
of Perl code require to automatically capitalize the first letter of
each word the user inputs:  "Uppercase".  Examples:

$query = televisions
becomes...
$query = Televisions

$query = stock market
becomes...
$query = Stock Market

THANKS!
Answer  
There is no answer at this time.

Comments  
Subject: Re: How to capitalize the first letter of each word in PERL
From: bozo99-ga on 09 Jul 2005 13:16 PDT
 
@words=split(/\s+/);
    for ($i=0;($i<@words);$i++) {
        if ($words[$i] =~ /([a-z])(.*)/) {
            $words[$i]= (uc $1) . $2;
        }
    }
    $text=join(" ",@words);
    printf("MixedCase: %s\n", $text);
Subject: Re: How to capitalize the first letter of each word in PERL
From: vladimir-ga on 10 Jul 2005 13:53 PDT
 
$query =~ s/\b(\w)/\u$1/g;

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy