Also known as RLH
set email [string map {at @ x . ext com} rlhicksatwehicksxext]
# 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] }