home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.perl:5561 fj.lang.perl:110
- Path: sparky!uunet!ogicse!orstcs!hanusj
- From: hanusj@storm.CS.ORST.EDU (Joe Hanus)
- Newsgroups: comp.lang.perl,fj.lang.perl
- Subject: Help with variable interpolation inside s///
- Keywords: variable interpolation, substitution
- Message-ID: <1992Aug27.203737.13356@CS.ORST.EDU>
- Date: 27 Aug 92 20:37:37 GMT
- Article-I.D.: CS.1992Aug27.203737.13356
- Sender: usenet@CS.ORST.EDU
- Followup-To: comp.lang.perl
- Organization: Computer Science Dept., Oregon State University
- Lines: 60
- Originator: hanusj@storm.CS.ORST.EDU
- Nntp-Posting-Host: storm.cs.orst.edu
-
-
-
- I have written a short capitalization script that's not working. The
- script assumes all words not found in a standard dictionary are proper
- nouns. Those found in the dictionary are capitalized by replacing
- with the word from the dictionary.
-
- The line giving the problem is commented
-
-
- Any help would be appreciated.
- -------------------------------------------------------
-
- #!/usr/bin/perl
-
- # get exceptions...
- open( CHANGES, "/usr/dict/words" );
- @words = <CHANGES>;
- close( CHANGES );
-
-
- # now do the capitalization for each line of the input file...
- while ( <> ) {
-
- # begin by assuming every word is a proper noun.
- # capitalize every word...
- tr/A-Z/a-z/;
- while ( ($firstletter) = /\b([a-z])/ ) {
- $firstletter =~ tr/a-z/A-Z/;
- s/\b([a-z])/$firstletter/;
- }
-
- # take care of the exceptions...
- foreach $word ( @words ) {
- # find the word without regard for case and replace
- # it with the word as it appears in /usr/dict/words.
- s/$word/$word/gi; # this is the line that's not working.
- # It should find the word in $word regardless of case and
- # substitute the word in $word as it was located in the
- # dictionary
-
-
- ---------------------------------------
-
-
-
-
- # print the line...
- print;
- }
-
- ------------------------------------------------------------------------------
- Joe Hanus | E-MAIL hanusj@bionette.cgrb.orst.edu
- Microbial Germplasm Database |
- Dept. of Botany and Plant Pathology | Phone (503)-737-5300
- Oregon State University | FAX (503)-737-3045
- Corvallis, OR 97331-2902 |
- ______________________________________________________________________________
- }
- --
-