【发布时间】:2018-11-24 18:01:12
【问题描述】:
我想复制文件的第 7-12 行,例如
this example .vect file,
进入同一目录中的另一个 .vect 文件。
我希望将每一行复制两次,并将每行的两个副本连续粘贴到新文件中。
这是我目前使用的代码,希望继续在 Perl 中使用这些方法/包。
use strict;
use warnings;
use feature qw(say);
# This method works for reading a single file
my $dir = "D:\\Downloads";
my $readfile = $dir ."\\2290-00002.vect";
my $writefile = $dir . "\\file2.vect";
#open a file to read
open(DATA1, "<". $readfile) or die "Can't open '$readfile': $!";;
# Open a file to write
open(DATA2, ">" . $writefile) or die "Can't open '$writefile': $!";;
# Copy data from one file to another.
while ( <DATA1> ) {
print DATA2 $_;
}
close( DATA1 );
close( DATA2 );
使用我在上面使用的相同打开和关闭文件语法来执行此操作的简单方法是什么?
【问题讨论】:
标签: perl file file-io scripting vector-graphics