home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4951 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  1.3 KB

  1. 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
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Capitalizing words?
  5. Message-ID: <1992Jul24.185601.29581@netlabs.com>
  6. Date: 24 Jul 92 18:56:01 GMT
  7. References: <1992Jul22.175327.15371@news.Hawaii.Edu>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 27
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <1992Jul22.175327.15371@news.Hawaii.Edu> bob@kahala.soest.hawaii.edu (Bob Cunningham) writes:
  14. : Surely there must be a nice little perl idiom to capitalize
  15. : lists of words, but I just can't seem to discover it.
  16. : How do you do it?
  17. : -- 
  18. : Bob Cunningham
  19. : bob@soest.hawaii.edu
  20. : School of Ocean & Earth Science & Technology, University of Hawaii
  21.  
  22. If you have a somewhat recent version, you can say something like
  23.  
  24.     foreach $word (@words) {
  25.         $word = "\u\L$word";
  26.     }
  27.  
  28. That forces the first letter uppercase and the rest lower case.  Just
  29. use \u to force only the first character.  Use \U to force all to upper case.
  30.  
  31. Alternatively, if you're stuck with an old version:
  32.  
  33.     foreach $word (@words) {
  34.     substr($word,0,1) =~ tr/a-z/A-Z/;    # first letter uppercase
  35.     substr($word,1) =~ tr/A-Z/a-z/;        # the rest lower
  36.     }
  37.  
  38. Larry
  39.