Posted to tcl by evilotto at Fri Nov 30 23:22:10 GMT 2012view raw

  1. proc autoclose_open {f} {
  2. set fd [open $f]
  3. catch {uplevel tailcall close $fd}
  4. return $fd
  5. }
  6.  
  7. proc whatever {a} {
  8. set data [read [autoclose_open $a]]
  9. puts "currently open: [chan names]"
  10. }
  11.  
  12. whatever /etc/passwd
  13. puts "now open: [chan names]"
  14.