TABLE OF CONTENTS
::pwtk::lineread
SYNOPSIS
proc ::pwtk::lineread {var file script} {
PURPOSE
Read entire file line-by-line and at each line execute a supplied script (script is executed at the level of the call).
ARGUMENTS
- var -- name of variable where the content of line will be stored
- file -- name of file to read
- script -- script to execute when line is read
CREDITS
Based on fileutils::foreachLine from tcllib (almost verbatim).
SOURCE
upvar $var line set fid [open $file r] set code 0 set result {} while { ! [eof $fid] } { gets $fid line set code [catch {uplevel 1 $script} result] if {($code != 0) && ($code != 4)} { break } } close $fid if { ($code == 0) || ($code == 3) || ($code == 4) } { return $result } if { $code == 1 } { global errorCode errorInfo return \ -code $code \ -errorcode $errorCode \ -errorinfo $errorInfo \ $result } return -code $code $result }