lakssreedhar has asked for the wisdom of the Perl Monks concerning the following question:
i have a file with words door,name,fame,dad,naming and so on.I have a rule file that whenever 'na' is followed by letter m then the letter m should be replaced by letter d and the whole word should be as na+d.so the output should be door,na+de,fame,dad,na+ding.The code below doesnt seems to work.
while(<>) { chomp; $inp_word4 = $_; @inp_word=split(//,$inp_word4); for($i=0;$i<@inp_word;$i++) { if(($inp_word[$i]=~/na/)&&($inp_word[++$i]=~/m/)) { $inp_word[++$i]=~s/m/d/; } print "$inp_word"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: replace a character based on rule file
by kcott (Archbishop) on Dec 04, 2012 at 08:17 UTC | |
Re: replace a character based on rule file
by karlgoethebier (Abbot) on Dec 04, 2012 at 07:59 UTC | |
Re: replace a character based on rule file
by graff (Chancellor) on Dec 05, 2012 at 02:41 UTC | |
Re: replace a character based on rule file
by nithins (Sexton) on Dec 04, 2012 at 13:24 UTC | |
Re: replace a character based on rule file
by karlgoethebier (Abbot) on Dec 04, 2012 at 08:57 UTC |
Back to
Seekers of Perl Wisdom