本文介绍了如何解决以下错误“未打开的文件句柄上的readline()..."?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何解决以下错误:
How would I solve the following error:
readline() on unopened filehandle UPPER at faStat2 line 86.
使用以下代码?
#!/usr/bin/perl
use strict;
use warnings;
...
my $cmd = $0;
$cmd =~ s#.*/##;
($#ARGV > 0) || die "Usage $cmd <tibcoUpperMDLog> <tibcoLowerMDLog> <outFile>\n\n";
open(my $UPPER, $ARGV[0]) || die "Unable to open $ARGV[0]\n";
open(my $LOWER, $ARGV[1]) || die "Unable to open $ARGV[1]\n";
...
while ($msg = <UPPER>) { getUpperBusTimeStampAndBatchSize(\$msg); } #This is the line that the error is complaning about
推荐答案
在这里,我同时介绍了实用和文体方面的变化.
Here I include both practical and stylistic chages.
#!/usr/bin/perl
use strict;
use warnings;
...
my $cmd = $0;
$cmd =~ s#.*/##;
die "Usage $cmd <tibcoUpperMDLog> <tibcoLowerMDLog> <outFile>\n\n"
unless @ARGV > 2;
open my $upper, '<', $ARGV[0] or die "Unable to open $ARGV[0]\n";
open my $lower, '<', $ARGV[1] or die "Unable to open $ARGV[1]\n";
...
while ($msg = <$upper>) { getUpperBusTimeStampAndBatchSize(\$msg); }
实用:
- 3个arg
open
(更安全,更现代) - 修复了对间接文件句柄的一致使用
风格:
- 使用
或而不是花括号和
||
(最不重要) - 与
@ARGV
进行比较,而不是与$#ARGV
进行比较(更具可读性,至少需要2个参数") - 对词汇变量(
my
)使用小写字母
- using
or
rather than braces and||
(least important) - compare against
@ARGV
rather than$#ARGV
(more readable, "need at least 2 args") - use lower case on lexical (
my
) variables
这篇关于如何解决以下错误“未打开的文件句柄上的readline()..."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!