in reply to Re^21: search and replace strings in different files in a directory
in thread search and replace strings in different files in a directory
Dear Monks
Thanks a mil in advance for your comments on how to comment one's code. I am sorry for my improper use of some of the technical terms that have led to some confusion. I did not know that there was so much to consider.
I went through some of the suggested links and promise to do better in the next project(s). It was very helpful and will surely be a great help in structuring my code and how I go about coding in general.
I changed the code a bit, i.e. substituted move with copy and got the results as specified by colleagues. I will put the script to test next time, there might be some issues with running the script on the server and not everybody has Perl installed, so I guess I'll be getting txt.file and run the script on my machine.
I would however like to post the recent version here so that it is accessible to others. It would also be grand if I got some feedback on the new comments.
Yes, before I forget, one of you mentioned that the following line would not quite match as intended.
sub Replace { my( $in, $bak ) = @_; path( $in )-> copy( $bak ); #rename $in to $bak my $infh = path( $bak )->openr_raw; my $outfh = path( $in )->openrw_raw; while( <$infh> ) { s{&}{&}g; ## will match more than what you want fix it s{&amp;}{&}g; s{\s>\s}{>}g; s{\s<\s}{<}g; print $outfh $_; } close $infh; close $outfh; }
That contributor was right, but the subsitution is only carried out the wrong way if there the source file has a particular structure in terms of the items to be substituted. I have not yet found when, since all the recent substitutions proved to be ok.
I'll let you guys know or some of you might have an idea
Thanks a mil to all contributors for your patience and providing the bits and pieces which have created this wonderful script.
Thank you and keep it going.
Kind regards
C
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^23: search and replace strings in different files in a directory
by PitifulProgrammer (Acolyte) on Sep 09, 2014 at 10:28 UTC | |
by Athanasius (Archbishop) on Sep 10, 2014 at 04:35 UTC | |
by PitifulProgrammer (Acolyte) on Sep 10, 2014 at 11:02 UTC | |
by PitifulProgrammer (Acolyte) on Sep 12, 2014 at 10:43 UTC | |
by Anonymous Monk on Sep 13, 2014 at 07:27 UTC | |
|