The return(0) are the usual code. I just commented them out while debugging to find out, on which point the open() fails. The gathered information showed me that the print behaves, like it was called after the close($fh). This behavior is, what I don't understand.

Even during testing, you should still check open for success, and in the case of failure, output $! to see the error. Instead of commenting out the or return(0);, replace it with or do { warn $file->{full_path}.": $!"; return 0 };

Again, in the code as you showed it above, if the open fails, then the code will continue on to the print $fh $file->{content};, which will cause the print() on closed filehandle $fh warning, and then the code should continue executing (the close, then the second print, and so on). Based on the information I see at the moment, the open is the most likely problem.

I'm sorry, but I don't know what you mean by "the print behaves like it was called after the close($fh)", because I don't know how you would have determined this. It's also unclear to me where the "Can't open perl script "../Path/to/file.pm": File or directory not found" message is coming from. This is why a Short, Self-Contained, Correct Example is important: could you edit down your code to the minimum required to reproduce the problem, while still being runnable? Also include any sample input, the expected output for that input, and the actual output you're getting instead, including any error messages, each within <code> tags. The aim is to provide a piece of code that we can simply download and run, and that reproduces the problem - you'll get help fastest that way. Often, this process will also help you see what the issue might be.

I think this works, but why does it stop to work, when I make it writing instead of reading and return()ing instead of die()ing?

Same thing, I'd have to see the actual code you're running to say more. See also How do I post a question effectively?


In reply to Re^3: foreach a writing open fails through not found file by haukex
in thread foreach a writing open fails through not found file by DomX

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.