home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5846 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.1 KB  |  32 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!melkur.dev.cdx.mot.com!mcook
  3. From: mcook@melkur.dev.cdx.mot.com (Michael Cook)
  4. Subject: Re: Case dependent substitution
  5. Message-ID: <mcook.716147058@melkur.dev.cdx.mot.com>
  6. Sender: news@merlin.dev.cdx.mot.com (USENET News System)
  7. Nntp-Posting-Host: melkur.dev.cdx.mot.com
  8. Organization: Motorola Codex, Canton, Massachusetts
  9. References: <1992Sep9.191433.25724@uvaarpa.Virginia.EDU>
  10. Date: Thu, 10 Sep 1992 17:44:18 GMT
  11. Lines: 19
  12.  
  13. Kevin Burton <noran!iowa!kburton@uunet.uu.net> writes:
  14.  
  15. >I would like to substitute an arbitrary pattern for another, but it all of
  16. >the alphabetic characters in the source pattern are upper case I would like
  17. >to case the replacement pattern to also force upper case substitution.
  18.  
  19. >For example:
  20.  
  21. >    substitute "abc" in "ABCxyzabc" with "xyz" produces "XYZxyzxyz"
  22. >    substitute "abc" in "abcxyzABC" with "xyz" produces "xyzxyzXYZ"
  23.  
  24. I was thinking that you could do something like this:
  25.  
  26.     s%abc% ($k = $&) =~ /a-z/ ? "\L$k" : "\U$k" %gie;
  27.  
  28. But it doesn't work.  It seems inside match (/a-z/) always fails, and you
  29. always get "\U$k".  Hmm...
  30.  
  31. Michael.
  32.