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

proc autoclose_open {f} {
  set fd [open $f]
  catch {uplevel tailcall close $fd}
  return $fd
} 

proc whatever {a} {
  set data [read [autoclose_open $a]]
  puts "currently open: [chan names]"
} 

whatever /etc/passwd
puts "now open: [chan names]"