Help with variable interpolation inside s/// 
Author Message
 Help with variable interpolation inside s///

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...

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...

      # 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;

Quote:
}

------------------------------------------------------------------------------

Microbial Germplasm Database         |
Dept. of Botany and Plant Pathology  | Phone  (503)-737-5300
Oregon State University              | FAX    (503)-737-3045
Corvallis, OR 97331-2902             |
______________________________________________________________________________
   }
--


Tue, 14 Feb 1995 04:37:37 GMT  
 Help with variable interpolation inside s///
:       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

I suspect you're running 4.019 or earlier-since this was supposedly fixed in
patch 20.  We're now at 4.035.

Larry



Wed, 15 Feb 1995 02:28:57 GMT  
 Help with variable interpolation inside s///

Quote:


>:       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

>I suspect you're running 4.019 or earlier-since this was supposedly fixed in
>patch 20.  We're now at 4.035.

>Larry

We are running perl version 4.035.  To verify this I ran
/usr/bin/perl -v.  Any other suggestions?

joe



Mon, 20 Feb 1995 05:22:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help with variable interpolation inside s/// (repost)

2. variable interpolation inside a regex

3. variable interpolation inside a hash

4. Variable Interpolation inside regular expression

5. Variable interpolation in the m// operator - help.

6. Help: variable interpolation in tr?

7. ANN: variable interpolation within strings help page

8. s///g interpolation and tied or overloaded variables (was: newbies question about backreference, please help)

9. Help with variable interpolation in reg-ex

10. Evaluating a Variable INSIDE a variable?

11. variable inside variable

12. scalar variable inside of a scalar variable

 

 
Powered by phpBB® Forum Software