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 contemplating the Monastery: (6)
As of 2015-07-03 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (49 votes), past polls