Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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".

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007181]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2018-03-21 07:32 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (264 votes). Check out past polls.