Apologies in advance if I'm posting this wrong, I kind of fell into a new role that needs more Perl knowledge that I'm used to, but trying to get through it.

So there's a file (will call it full file) that was created wrong by my processor, it can't easily be regenerated so I need to try and correct it. Perl is really the only scripting language I'm familiar with to even attempt at modifying this type of data, if there's something easier just let me know.

For starters the file was built from multiple data fields, and one of the important ones was joined without a separator, an example is below.

path: /unix/path/to/folder/is/here
file: file_name.sh
joined: /unix/path/to/folder/is/herefile_name.sh

As you can see this example isn't too bad, it could be manually updated to joined: /unix/path/to/folder/is/here/file_name.sh
The problem is there's thousands of these mistakes in an attribute called CMD, so it ends up looking like CMD="/unix/path/to/folder/is/herefile_name.sh" along with other attributes for each job like name, system, etc.

My thought was to load the file I need to update into an array and then try to parse the array one line at a time. I have a list of all the folder paths in a .txt file that I was hoping to use as a reference file somehow. So it would read the folder paths into an array, check each line of the full file and replace the value with the reference value if found and write it back to the file.
$references = join '|', map {chomp; qr/\Q$_\E/} <$file_paths>; $regex = qr|\b($references)\b|; while (<>) { $_ =~ s/($regex)(.*)/$1\/$2/; print; }
Essentially I have a bunch of lines scatted throughout the file that have paths that need to be updated, I think updating the file from a reference list with regex is my best option from researching, the concept should work in theroy I just can't really get my head around the implementation. Any help is appreciated.

In reply to In place replacement from reference list by Misstre

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.