Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?

by Aristotle (Chancellor)
on Jan 13, 2007 at 23:51 UTC ( #594579=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
in thread How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?

In my system, the final string on STDERR gets printed when the close above is commented; uncommenting the close triggers the fatal error:

And thatís exactly the point: when you have an explicit close, you can make it throw an exception; when you omit the close, the error is silent. But I want to omit the close and still get an exception. Fatal wonít help me there.

Thanks for the pointer about the loop device though! All I can say in retrospect is, díuh. However, Linux has an easier way, mentioned by Zaxo in the old thread from gaal: thereís a /dev/full device where writing always fails with ENOSPC.

Makeshifts last the longest.


Comment on Re^2: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
Re^3: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
by BrowserUk (Pope) on Jan 14, 2007 at 00:01 UTC

      NoÖ

      $ perl -MFatal=open,close,syswrite
      -e'open $fh,">/dev/full"; syswrite $fh, 1; close $fh'
      Can't syswrite(GLOB(0x8130c24), 1): No space left on device at (eval 3) line 3
      	main::__ANON__('GLOB(0x8130c24)') called at -e line 1
      $ perl -MFatal=open,close
      -e'open $fh,">/dev/full"; print { $fh } 1 or die "$!\n"; close $fh'
      Can't close(GLOB(0x8130c24)): No space left on device at (eval 2) line 3
      	main::__ANON__('GLOB(0x8130c24)') called at -e line 1

      Ö not with buffered I/O.

      Makeshifts last the longest.

Re^3: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
by polettix (Vicar) on Jan 14, 2007 at 01:01 UTC
    Oh, I misunderstood that you didn't know for sure about Fatal's behaviour:
    In the simplest case, use Fatal qw( :void close ); would work for this, but I strongly doubt it, and in any case I canít think of a good way to purposefully trigger a close failure in order to test it.
    And yes... the loop device rocks :)

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-08-01 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls