in reply to Replacing a substring from a string in a file

pop18,

please don't delete the original text of your posts after your questions have been answered. Fellow monks who happen to read the answers won't see what the original question was, and thus can't learn from the question / answer play any more. Just leaveyour orignal post (OP) as it is, and insert lines below it marked with "update:"

Please read the entry How do I change/delete my post? in PerlMonks FAQ.

Thank you.

OP text:


Dear All, I need to replace a substring only from a string in a file. I tried with the following coding. But i got the result by replacing all the specified substring in the whole document. I need the substring to be replaced inside the specified string only.

I want to replace "\limits" inside "$ a+b=\sum\limit_a^{n-j}$"

######### open IN, "abc.xml", or die "$!\n"; open OUT, ">iabc.xml", or die "$!\n"; @txt=<IN>; foreach $xabc (@txt) { $find=~ m/\$([^\$]*)\$/g; $find = "\\limits"; $replace = ""; $find = quotemeta $find; $xabc =~ s/$find/$replace/g; print OUT $xabc; } close($xabc);

Please Help.

Thanks
POP


--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}