- 论坛徽章:
- 0
|
本帖最后由 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
从代码上看,文件句柄确实已经打开了。百思不得其解。
文件句柄的文件路径也没有问题! |
|