e.g.
I am the sunny boy.
to
KKaKKKKeKKKKKKKbKKK
Assuming you mean lower case [abcde], you can do it like this:
$a = 'I am the sunny boy.';
($b = $a) =~ s/[^abcde]/K/g;
print "$b\n";
KKaKKKKeKKKKKKKbKKK
> print "$b\n";
And to make it case-insensitive just add 'i' to the match flags:
($b = $a) =~ s/[^ABCDE]/K/gi;
Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de
use the 'tr' operator:
my $text = 'I am the sunny boy.';
$text =~ tr/a-e/K/c;
(http://perldoc.perl.org/perlop.html)
Regards
M.
perldoc perlop --> tr/// --> option c:
c Complement the SEARCHLIST.
>I am the sunny boy.
>
>to
>
>KKaKKKKeKKKKKKKbKKK
But your text didn't contain any of [ABCDE], so every single character
should be 'K', shouldn't it?
jue
It did.
hp
I think you may have missed the "case-insensitive" requirement
above. Which also means, incidentally, that the OP will need to use
s/// instead of tr///, given that the latter doesn't support the "i"
modifier.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
SP> Jürgen Exner <jurg...@hotmail.com> writes:
>> "Ela" <e...@yantai.org> wrote:
>>> how to replace a line's all characters (case-insensitive) NOT equal to any
>>> of say, [ABCDE] to K?
>>
>> perldoc perlop --> tr/// --> option c:
>> c Complement the SEARCHLIST.
>>
>>> I am the sunny boy.
>>>
>>> to
>>>
>>> KKaKKKKeKKKKKKKbKKK
>>
>> But your text didn't contain any of [ABCDE], so every single character
>> should be 'K', shouldn't it?
SP> I think you may have missed the "case-insensitive" requirement
SP> above. Which also means, incidentally, that the OP will need to use
SP> s/// instead of tr///, given that the latter doesn't support the "i"
SP> modifier.
tr/// may not have /i but it can still do the job with:
tr/abcdeABCDE/K/c
now if the list of letters gets long it can become messier but that is
up to the OP.
uri
--
Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
Oooops, never mind.
jue