ppp ppp wrote:
> Hi All ;

Hello,

> Subject: Re: Grep through a log file

It doesn't look like you are replying to the OP and your question is not about
'grep' so you should start a new thread instead of replying to an existing one.


> I am new to this group.I am just started to learn perl.I want to program
> in perl or C that it input text file(.txt) and it should find every
> Uppercase letters(Capital letter) in the input file converts every capital
> letter say with one letter d and lower case letters(small letters)
> replaces with letter O.
> 
> for eg.(input file- eg1.txt)
>>protein1
> afagaDRTYUagagfaa
>>protein 2
> DFafagagRTUI
> 
> output file (eg2.txt)
>>protein1
> ooooodddddooooooo
>>protein2
> ddoooooodddd
>    
>   My code 
>    
>   while($string=<>) {
>   $string=~ tr/[A-Z,a-z]/[d,o]/ ;

The tr operator translates characters so you are translating '[' to '[' and
'A' to 'd' and 'B' to ',' and 'C' to 'o' and the characters
'DEFGHIJKLMNOPQRSTUVWXYZ,abcdefghijklmnopqrstuvwxyz]' to ']'.  To use tr/// to
do what you want you need to use:

$string=~ tr/A-Za-z/ddddddddddddddddddddddddddo/;

Or do it in two steps;

tr/a-z/o/, tr/A-Z/d/ for $string;

Or you could use the substitution operator which will let you change
non-English alphabetical characters:

s/[[:lower:]]/o/g, s/[[:upper:]]/d/g for $string;


>   print $string ;}



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to