home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!dog.ee.lbl.gov!network.ucsd.edu!nic!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: Capitalizing words?
- Message-ID: <1992Jul24.185601.29581@netlabs.com>
- Date: 24 Jul 92 18:56:01 GMT
- References: <1992Jul22.175327.15371@news.Hawaii.Edu>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 27
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Jul22.175327.15371@news.Hawaii.Edu> bob@kahala.soest.hawaii.edu (Bob Cunningham) writes:
- : Surely there must be a nice little perl idiom to capitalize
- : lists of words, but I just can't seem to discover it.
- :
- : How do you do it?
- : --
- : Bob Cunningham
- : bob@soest.hawaii.edu
- : School of Ocean & Earth Science & Technology, University of Hawaii
-
- If you have a somewhat recent version, you can say something like
-
- foreach $word (@words) {
- $word = "\u\L$word";
- }
-
- That forces the first letter uppercase and the rest lower case. Just
- use \u to force only the first character. Use \U to force all to upper case.
-
- Alternatively, if you're stuck with an old version:
-
- foreach $word (@words) {
- substr($word,0,1) =~ tr/a-z/A-Z/; # first letter uppercase
- substr($word,1) =~ tr/A-Z/a-z/; # the rest lower
- }
-
- Larry
-