Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: replace a character based on rule file

by graff (Chancellor)
on Dec 05, 2012 at 02:41 UTC ( [id://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".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-20 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found