Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: replace a character based on rule file

by graff (Chancellor)
on Dec 05, 2012 at 02:41 UTC ( #1007181=note: print w/ replies, xml ) Need Help??


in reply to replace a character based on rule file

The reason the OP code doesn't work is that the @inp_word array contains elements of one character each, because it gets the output of split(//,$inp_word4); But then your logic depends on some element of @input_word containing "na", which can never happen.

If I understand your task description correctly, I think you just need a basic regex substitution:

while(<>) { s/(?<=na)m/+d/g; print; }
The (?<=na) part there is called a "positive look-back assertion" - check that out on perlre. It says that any "m" will be replaced by "+d" if it's preceded by "na".


Comment on Re: replace a character based on rule file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007181]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-09-22 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls