Artifact 2d09da027b51c0c3fd0193557944dd40390fd3c786d616f5953b2964857d3e85:
- File library/foreachline.tcl — part of check-in [3300680ebd] at 2023-05-29 12:11:30 on branch tip-670 — Basic implementation of TIP 670 (user: dkf, size: 531) [annotate] [blame] [check-ins using]
# foreachLine: # Iterate over the contents of a file, a line at a time. # The body script is run for each, with variable varName set to the line # contents. # # Copyright © 2023 Donal K Fellows. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # proc foreachLine {filename varName body} { upvar 1 $varName line set f [open $filename "r"] try { while {[gets $f line] >= 0} { uplevel 1 $body } } finally { close $f } }