Replace glob "$folder\*.nfo" with glob "$folder\\*.nfo" so the backslash doesn't disappear.

Replace open my $fh, '<$filename' with open my $fh, '<', $filename because the single quotes in your code don't allow interpolation of the variable. Change the second open similarly. (Thanks to bart for noticing this second error.)

Also, you're overwriting the same output file each time, so in the end you'll only get a copy of one file, the one glob finds last.

If you want to debug such code alone, it could be worth to add a statement like warn "copying ($filename)\n"; to the use_contents function, so that you can see how many times the function gets called and for what files.


In reply to Re: open file and write the content into another file by ambrus
in thread open file and write the content into another file by cesapun

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.