home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!rpi!uwm.edu!ogicse!orstcs!prism!jacobsd
- From: jacobsd@prism.cs.orst.edu (Dana Jacobsen)
- Newsgroups: comp.lang.perl
- Subject: Re: Help with variable interpolation inside s/// (repost)
- Keywords: variable interpolation, substitution
- Message-ID: <1992Sep12.033628.2470@CS.ORST.EDU>
- Date: 12 Sep 92 03:36:28 GMT
- References: <1992Sep11.222422.24918@CS.ORST.EDU>
- Sender: usenet@CS.ORST.EDU
- Organization: Oregon State University, Computer Science Dept
- Lines: 51
- Nntp-Posting-Host: prism.cs.orst.edu
-
- In <1992Sep11.222422.24918@CS.ORST.EDU> hanusj@storm.CS.ORST.EDU (Joe Hanus) writes:
- >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?
-
- While I can't solve the problem (it looks like your code should work
- to me), I can suggest a workaround that not only works, it is much faster
- than the method you're using. Hint: loop over the sentence, not the
- dictionary. I also use the "\u" and "\L" operaters defined on page 70 of
- the Camel book to do the capitalization.
-
- #!/usr/local/bin/perl
-
- open( CHANGES, "/usr/dict/words" );
- while (<CHANGES>) {
- chop;
- $realcap = $_;
- # convert into "Captilized Format"
- s/^(\S)(\S*)/\u$1\L$2/;
- $rwords{$_} = $realcap;
- }
- close( CHANGES );
-
- while ( <> ) {
- s/\b(\S)(\S*)\b/\u$1\L$2/g;
- foreach $word ( split(/\W/) ) {
- s/\b$word\b/$rwords{$word}/g if $rwords{$word};
- }
- print;
- }
-
- exit 0;
-
- >------------------------------------------------------------------------------
- >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 |
- >______________________________________________________________________________
- --
- Dana Jacobsen I that wes in heill and gledness
- jacobsd@cs.orst.edu am trublit now with gret sikness
- jacobsd@solar.cor2.epa.gov and feblit with infirmetie
- Computer Sciences Corporation Timor mortis conturbat me.
-