home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5882 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  2.2 KB

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