Also known as [RLH] ***Email*** ====== set email [string map {at @ x . ext com} rlhicksatwehicksxext] ====== ***LinkedIn*** http://www.linkedin.com/pub/robert-hicks-cissp/18/936/60%|%My Public Profile%|% ***To do list*** * Learn one or more of the following: [Snit] [XOTcl] [Itcl] [Gnocl] [C] * Encourage the [Tcl Core Team] because they do a ''great'' job! *** Books I need to get*** * Tcl and Tk Programming for the Absolute Beginner * '''Tcl and the Tk Toolkit''' * Tcl 8.5 Network Programming [x] * Tcl and Tk 8 Programming Cookbook * '''incr Tcl from the Ground Up''' ***Things I like*** * I love the Tcl community * I like that Tcl is different from other dynamic languages syntax wise This is just a simple attempt at adding a 'with' command like other language such as Python have. ====== # futils.tcl -- # # This package provides some extra file utilities that are not in the core or # in tcllib. # package provide futils 1.0 #--------------------------------------------- # Create the namespace #--------------------------------------------- namspace eval ::futils { # export the commands namespace export with } # ::futils::with -- # # This proc ensures that files get closed even when errors happen. It is # inspired by the Python language with function. # # Arguments: # file file to open # # Examples: # ::with [open foo.txt w] as file { # puts $file "Hello!" # } # # ::with [open foo.txt r] as file { # set data [read $file] # puts $data # } # proc ::futils::with {} { uplevel 1 [list set $name $file] if [catch {uplevel 1 [list eval $block]}] result { puts stderr "Warning: $result" } uplevel 1 [list close $file] } ====== <> Category Person