Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: foreach a writing open fails through not found file

by DomX (Novice)
on Jun 23, 2019 at 14:29 UTC ( [id://11101762]=note: print w/replies, xml ) Need Help??


in reply to Re: foreach a writing open fails through not found file
in thread foreach a writing open fails through not found file

Hello haukex,

I think this is a misunderstanding. 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.

Your third example of your post you mentioned in "I posted", looks the very same to me like my foreach but reading. 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?

Replies are listed 'Best First'.
Re^3: foreach a writing open fails through not found file
by haukex (Archbishop) on Jun 23, 2019 at 15:03 UTC
    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?

      Sorry guys, this was just a failure of mine: I missed to create the containing directory...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11101762]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found