home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5561 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  2.2 KB

  1. Xref: sparky comp.lang.perl:5561 fj.lang.perl:110
  2. Path: sparky!uunet!ogicse!orstcs!hanusj
  3. From: hanusj@storm.CS.ORST.EDU (Joe Hanus)
  4. Newsgroups: comp.lang.perl,fj.lang.perl
  5. Subject: Help with variable interpolation inside s///
  6. Keywords: variable interpolation, substitution
  7. Message-ID: <1992Aug27.203737.13356@CS.ORST.EDU>
  8. Date: 27 Aug 92 20:37:37 GMT
  9. Article-I.D.: CS.1992Aug27.203737.13356
  10. Sender: usenet@CS.ORST.EDU
  11. Followup-To: comp.lang.perl
  12. Organization: Computer Science Dept., Oregon State University
  13. Lines: 60
  14. Originator: hanusj@storm.CS.ORST.EDU
  15. Nntp-Posting-Host: storm.cs.orst.edu
  16.  
  17.  
  18.  
  19. I have written a short capitalization script that's not working. The
  20. script assumes all words not found in a standard dictionary are proper
  21. nouns.  Those found in the dictionary are capitalized by replacing
  22. with the word from the dictionary. 
  23.  
  24. The line giving the problem is commented
  25.  
  26.  
  27. Any help would be appreciated.
  28. -------------------------------------------------------
  29.  
  30. #!/usr/bin/perl
  31.  
  32. # get exceptions...
  33. open( CHANGES, "/usr/dict/words" );
  34. @words = <CHANGES>;
  35. close( CHANGES );
  36.  
  37.  
  38. # now do the capitalization for each line of the input file...
  39. while ( <> ) {
  40.  
  41.    # begin by assuming every word is a proper noun.
  42.    # capitalize every word...
  43.    tr/A-Z/a-z/;
  44.    while ( ($firstletter) = /\b([a-z])/ ) {
  45.       $firstletter =~ tr/a-z/A-Z/;
  46.       s/\b([a-z])/$firstletter/;
  47.    }
  48.  
  49.    # take care of the exceptions...
  50.    foreach $word ( @words ) {
  51.       # find the word without regard for case and replace
  52.       # it with the word as it appears in /usr/dict/words.
  53.       s/$word/$word/gi;   # this is the line that's not working.
  54.       # It should find the word in $word regardless of case and 
  55.       # substitute the word in $word as it was located in the 
  56.       # dictionary
  57.  
  58.  
  59. ---------------------------------------
  60.  
  61.  
  62.  
  63.  
  64.    # print the line...
  65.    print;
  66. }
  67.  
  68. ------------------------------------------------------------------------------
  69. Joe Hanus                            | E-MAIL hanusj@bionette.cgrb.orst.edu
  70. Microbial Germplasm Database         |
  71. Dept. of Botany and Plant Pathology  | Phone  (503)-737-5300
  72. Oregon State University              | FAX    (503)-737-3045
  73. Corvallis, OR 97331-2902             |
  74. ______________________________________________________________________________
  75.    }
  76. --
  77.