Not what you asked for, but re the backup files lack of usefulness, you might consider using a flag to indicate that a particular file has or has not already been changed... and use the value of that flag to determine whether to rename the file being changed to -- say -- file.old, if you're making the first change of this run or to .bak, on subsequent encounters with the same file.

Alternately, you could make your sub do a rename to file.(OPTIONAL: time_of_action).old, unless the particular file.old exists already, in which case, it should rename to file.bak.

The second notion is probably simpler to implement, but will rely on good housekeeping. I gather you want to be able to compare or diff the original with the revisions after this snippet completes, but then, immediately, you have to unlink or del the .olds, because failing to do so will bork the logic on the next run (which might even be before your first is finished in a multi-user environment).


In reply to Re: Perl File Editing Subroutines, Any ideas? by ww
in thread Perl File Editing Subroutines, Any ideas? by symgryph

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.