增量文件名TCL

问题描述 投票:0回答:1

我的输入文件有5行,所有5行都打印到1个文件中。如何在看跌期权中在一个文件中打印每一行?如何增加现有文件名?

# Input file
1 2 3 4
1 3 4 5
2 3 4 5
1 2 3 4
set infile  [open "infile.txt" r]
set outfile [open "outfile.txt" w]
set count    0

     while {[gets $infile line] > 0} {
        incr count

          puts $outfile"$count" "I want to split the input file into 4 different files. Each file is one line"      
    }

似乎TCL不喜欢上述语法?我希望得到outfile1,outfile2 .....

tcl filenames
1个回答
0
投票

[执行时:

set outfile [open "outfile.txt" w]

与[outfile.txt]相关联的文件句柄outfile被创建以供写入。该文件句柄将一直与打开的文件关联,直到它已经关了。如果要输出到其他文件,则必须打开其他文件文件并将文件句柄分配给变量。

出于您的问题,您需要打开输出文件在while循环中。

© www.soinside.com 2019 - 2024. All rights reserved.