Chinaunix
标题:
请问文件句柄“关闭”的问题!
[打印本页]
作者:
tempo8
时间:
2012-05-19 22:41
标题:
请问文件句柄“关闭”的问题!
本帖最后由 tempo8 于 2012-05-19 22:44 编辑
请问文件句柄“关闭”的问题!
源于
http://bbs.chinaunix.net/thread-3744895-1-1.html
my @content;
my $word;
my %hash_file2;
my $i = 1;
my $count;
open FD1, "<file1";
open FD2, "<file2";
while(<FD2>) {
chomp;
$hash_file2{$i} = $_;
$i++;
}
while ($word = <FD1>) {
chomp($word);
$count = grep {/\b$word\b/} values %hash_file2;
push @content, $word if $count > 0;
}
print @content;
复制代码
C:\strawberry\perl\bin>perl word-map.pl <A.txt <B.txt >111.txt
运行时出现问题:
while(<FD2>)
{#问题来啦:readline() on closed filehandle FD2
while ($word = <FD1>)
{#问题也来啦:readline() on closed filehandle FD1
从代码上看,文件句柄确实已经打开了。百思不得其解。
文件句柄的文件路径也没有问题!
作者:
py
时间:
2012-05-20 09:34
养成好习惯
open FH, '<', './filename' or die $!;
复制代码
作者:
tempo8
时间:
2012-05-20 20:56
本帖最后由 tempo8 于 2012-05-20 21:02 编辑
py 发表于 2012-05-20 09:34
养成好习惯
高人一语道破天机!
为么事绝对路径这么好使?!
可是怎么解决忽略中文的问题呢?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2