I thank you for the examples

Wow, that's a lot of code. The whole purpose of using an external library is to reduce how much code you have to write!

Didn't you notice the reduction? There is no 3 argument open , no "or die" verbosity? I think thats neat

... edit_file_lines .... neat, huh? For an in-place edit, that's the way to go.

Did you know that reads the whole file into memory? It limits the size of files you can edit to the amount of RAM you have (and perl has access to)

That /\>/ hints to me the OP might be dealing with gigabyte sized files, probably a good idea to avoid slurping

When I need to do something more with the lines in the file, I usually skip the full monty and go with File::Slurp::Tiny, but in this case that takes a little more coding since you have to build up an array to pass to its write_file method, and you need to create an output file:

That has the same issue, it read whole file into memory/an array, duplicate this array, write it out ; Too much memory requirement based on size of file.


In reply to Re^3: How do I modify a line within the file itself? by Anonymous Monk
in thread How do I modify a line within the file itself? by newbie4659

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.