Summary of problem: You are never writing the data out to a file.

You read it from file.
You change it in scalar (memory).
You print to console.

Missing is the step to write it to an output file.

As noted by others, one approach is slurp-digest-spew (open, read to array, close, modify array, open for write, write, close. It is probably more efficient to perform the modifications as you read the data, which your script already does. This has the cost of increased risk of file corruption if power goes out during the spew phase, and it consumes more memory for the array. It has the advantage of being easy to write, and less disk space consumed.

Another approach is to write a temporary output file. open input, open output, read-process-write loop, close, close, rename or unlink input file (make sure rename works if you use that!), rename output file to input file. This has the advantage of reduced vulnerability to file corruption due to power failure at the cost of increased disk consumption. It does use less memory, as there is no array involved.

But the reason the file is unchanged when you cat it is because you didn't change it in your script. You only write the modified data to the screen.


In reply to Re: replace text by marinersk
in thread replace text by dawg31wh

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.