in reply to Case-sensitive substitution with case-insensitive matches
Update: This and my other answer slightly updated, I just like it better now :-)#!/usr/local/bin/perl -l -w use strict; my $str = "SAdBoy"; $str =~ s/($str)/fix_case($1, 'badgirl')/eig; print $str; sub fix_case { my $match_word = shift; my $replace_word = shift; my $i = 0; for (split '', $match_word) { next if $_ eq lc; substr($replace_word, $i, 1) = uc substr($replace_word, $i, 1); } continue { $i++ } return $replace_word; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Case-sensitive substitution with case-insensitive matches
by chipmunk (Parson) on Dec 02, 2000 at 21:31 UTC |