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


In reply to Masters of Loops and Filehandles by pbyfire

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.