home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!orstcs!hanusj
- From: hanusj@storm.CS.ORST.EDU (Joe Hanus)
- Newsgroups: comp.lang.perl
- Subject: Help with variable interpolation inside s/// (repost)
- Keywords: variable interpolation, substitution
- Message-ID: <1992Sep11.222422.24918@CS.ORST.EDU>
- Date: 11 Sep 92 22:24:22 GMT
- Article-I.D.: CS.1992Sep11.222422.24918
- Sender: usenet@CS.ORST.EDU
- Followup-To: comp.lang.perl
- Organization: Computer Science Dept., Oregon State University
- Lines: 63
- Originator: hanusj@storm.CS.ORST.EDU
- Nntp-Posting-Host: storm.cs.orst.edu
-
-
-
-
- We 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
- We are using perl 4.035
-
- Can you pinpoint my problem or suggest a work-around?
- 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...
- # for each word read in from the list
- foreach $word ( @words ) {
-
- s/$word/$word/gi; # this is the line that's not working.
-
- # find the word in $word regardless of case and
- # substitute the word in $word as it was capitalized 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 |
- ______________________________________________________________________________
-