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