in reply to Pattern Matching: Case-Conservation
Here's the first part of the text from my docs:
How do I substitute case insensitively on the LHS while preserving case on the RHS?
Here's a lovely Perlish solution by Larry Rosler. It exploits properties of bitwise xor on ASCII strings.
$_= "this is a TEsT case"; $old = 'test'; $new = 'success'; s{(\Q$old\E)} { uc $new | (uc $1 ^ $1) . (uc(substr $1, -1) ^ substr $1, -1) x (length($new) - length $1) }egi; print;
But you really should read the rest of the entry
update: I just realized that I may have slightly misread what you wanted to do. That's okay though as the technique (using the ^ operator) is basically the same. :-)
|
|---|