On Saturday 05 January 2008 20.21.59 Eric Wilhelm wrote: > Even if it weren't a system handle, in what situation does print() > return false? > > 1. Closed handle > 2. Unopened handle > 3. Disk full > > Unless I've missed one, you don't need to check the return value of > print. > > I will even say it is wrong to do so in most situations. The exception > would be unattended long-running processes where lots of print() calls > will happen before a close(). Yes 'print STDOUT' will fail with $! > = "No space left on device" when stdout is redirected, but I hardly > think catching that is worth sprinkling so many 'or die "$!"' > statements around in your code.[1] Wrong because of the sprinkling ?
> [1] If anything, at least a print() replacement via some XS code which > throws errors wouldn't cost you an arm+leg at runtime (plus it saves > the bleeding eyeballs.) I of course agree that writing 'or die $!' a million time is a painful and unaesthetic. In the object oriented modules I write, I have started using code reference instead for 'print' so there is only one place to test. 'print' is not overridable and you can't simply use 'Fatal' on it either. I asked p5p if there were chances that 'print' would become overridable some day an the answer was 'no'. Do you happend to know something about replacing 'print' with XS code short of patching perl (which doesn't sound like a good idea) > For #3, you need to check the return on close(). > > For #1 and #2 you need to have 100% coverage with warnings enabled and > test NoWarnings (and check the return code of open().) Standard filehandles are neither opened nor closed often by developer. The above still applies for the other filehandles. But in that case I, other can be less anxious if they want to, would still think that checking the return value of 'print' is worth it. For example, the prints are done to a journaling log, would it make sense to continue working on the journaled files knowing that the final write is going to fail anyway? There is a difference between a journaling log and printing to STDOUT. No doubt my example is extreme and only that example may need extreme precausions. Cheers, Nadim.