|Perl Monk, Perl Meditation|
Masters of Loops and Filehandlesby pbyfire (Novice)
|on May 09, 2012 at 22:36 UTC||Need Help??|
pbyfire has asked for the
wisdom of the Perl Monks concerning the following question:
Hello Perl Monks,
I am at wits end trying to accomplish something that I am sure is simple to many of you. Although I have a million lines of code attempts at this patched together from examples all over the internet I will not burden you with them.
Here is what I need to do:
Process all files in a single directory by seeking to a fixed position in each file and reading a string which will need to be replaced globally in each of the files read.
The problem I am having is that I only know that the string to be replaced is 10 characters long and are never the same thus seek and read or sysread will discover what they are but I have not been able to save them to a variable for use in a sed like statement such as 's/$stringfound/$stringreplacement/g' The global replacement does not work on an open FileHandle within the loop.
Yes, I know that a global substitution is easy as a one liner from the command line with redirects but I need to do this within a loop to discover the replacement string and perform a global replace on multiple files.
All suggestions, examples etc are greatly appreciated.
Bless the monks for their patience with beginners - pbyfire