You are doing a couple things wrong here. As blaze mentioned, you'll need to chomp your input otherwise $file will have a "\n" on the end of it and that'll be assumed to be part of the filename by your open().

You open the file for reading but then you attempt to print to it with your print FILE line. Not only will that fail because your file isn't open for writing, it wouldn't work as you might expect anyway because of the way you are mixing reads and writes. It would be better to write your results out to another file. Even when you use perl's -i flag or $^I variable, it writes the results out to a temporary file first.

You are also closing the file in your continue block.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: File Handle Basics by sauoq
in thread File Handle Basics by airblaine

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.