【发布时间】:2011-05-31 02:44:15
【问题描述】:
我正在尝试编写一个 perl 脚本,首先它会打开一个目录(目录中有多个文件),其次它会读取目录中的文件 strong>,然后将单词逐行放入数组中,并将这些单词作为参数发送到 c++ 程序。 我尝试编写脚本,但处理文件时出现问题,它打开目录但我无法访问文件,
这类问题应该有不止一个答案,我的脚本是:
my $directory = '.';
my @connection;
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR)) {
next if ($file =~ m/^\./);
print "$file\n";
open (MYFILE, '$file') or die $!;# error is in here, can not open/
while (<MYFILE>)
{
# split each input line; words are separated by whitespace
for $word (split)
{
#put the words in an array
#no need to store words, can be overwritten in array
#system() for calling c++ code
}
}
}
【问题讨论】: