note
Zaxo
<p>As far as I know, you can't [<b>Added: </b>There is a way, see my other reply below, [id://394196]]. Observe,
<code># use Fatal qw/open print close/;
use Fatal qw/open close/;
my $result = eval {
open my $fh, '>', '/dev/full';
print $fh "Foo\n" or die $!;
};
print $result ? $result : $@, $/;</code>
prints '1', the result of printing to the filehandle.</p>
<p>Placing an explicit close after the print statement gives something like,
<code>Can't close(GLOB(0x804b548)): No space left on device at (eval 2) line 3
main::__ANON__('GLOB(0x804b548)') called at -e line 1
eval {...} called at -e line 1</code>
That uses the handy <tt>/dev/full</tt> device of linux, for which writes always fail with <tt>ENOSPC</tt>. The failure would have occurred on print if we had set $fh to autoflush or had printed more than a buffersworth of text.</p>
<p>For careful error handling, you should [close] your lexical handles as if they didn't know how to do it for themselves.</p>
<p><b>Update: </b>[gaal]++ points out an error. Corrected.</p>
<div class="pmsig"><div class="pmsig-82147">
<p>After Compline,<br/>Zaxo</p>
</div></div>
394068
394068