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?
| [reply] [Watch: Dir/Any] [d/l] [select] |
Sorry guys, this was just a failure of mine: I missed to create the containing directory...
| [reply] [Watch: Dir/Any] |