Aside from adding $! to get the systems error message in your die you have a number of other errors.

You don't seem to want printf. print FILE $line will just print out the line to the filehandle FILE. printf in Perl means print formatted and needs the format specified. See perlman:perlfunc for details. Write a bit of C by any chance :-)

Even with print this will still not modify you files as you obviously want to do. This is beacuse you open the file without an input operator. These include < for open for reading > for open for writing and >> for open for appending. See perlman:perlop for more details.

To find the solution you want do a Super Search for "in place edit" in the text and "chipmunk" for the author. You will find Re: modifying a text file on Win32 which does part of what you want. Have a look at the whole thread

Update

This is so common that a snippet seemed in order. This is at Inplace Editing

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: BAsic File I/O by tachyon
in thread BAsic File I/O by Anonymous Monk

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.