Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Handling multiple output files simultaneously using arrays of filehandles and filenames

by talexb (Chancellor)
on Jan 21, 2021 at 16:30 UTC ( [id://11127210]=note: print w/replies, xml ) Need Help??


in reply to Handling multiple output files simultaneously using arrays of filehandles and filenames

What does Perl say?

Just looking at this code, I see you are missing $! in your error message -- and that would tell you what the problem is. You also don't need "\n" in the die message.

It also looks like you have not defined $filenamefirstpart, so strict should report that's undefined.

I highly recommend you put together a self-contained, working example before you post. We'll help you with stuff you don't understand, but you need to have a working example that compiles first.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

  • Comment on Re: Handling multiple output files simultaneously using arrays of filehandles and filenames
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Handling multiple output files simultaneously using arrays of filehandles and filenames
by Cosmic37 (Acolyte) on Jan 21, 2021 at 20:22 UTC
    Thank you for that interesting advice. Please may I ask what is the basis upon which you presume that I need $! and no \n in the die output? Is this not a free choice for the programmer? Is there a particular weakness you are referring to?

      The $! literally tells you what the error is. I have no idea why you would want to throw that information away by not displaying it.

      The "\n" in the output isn't necessary because die takes care of adding a newline automatically -- but I guess that's a matter of taste. Add one if you like. I never add newlines to die or warn statements.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      You need $! because otherwise you only know that there's been an error of some sort and not what specific error occurred. Just grobbling through the open(2) manual page on OS X there's 22 distinct error codes in 32 different cases which can be returned at the C level.

      The trailing newline is mostly an aesthetic choice though.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        nitpick:

         The trailing newline is mostly an aesthetic choice though. 

        I learned here at the Monastery (sorry can't remember by whom) that calling die with a final newline will cause it to omit the line number. It will be less verbose.

        die "aaa"; aaa at - line 1. die "aaa\n"; aaa
        Thanks for this opinion. I think its good advice and good practice in most cases but that there may be cases when a programmer chooses to do something different, believing (almost insisting) themselves to be a free person living in a free world (I know; how naive). I am very grateful for your engagement, and all those who have offered advice and opinion in response to my question.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2024-04-19 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found