【发布时间】:2010-11-05 04:28:00
【问题描述】:
结束这个问题。会喝红牛。睡觉。编写代码并返回带有单元测试用例的全新问题。
更新:新文件是here
配置文件也是here
我再次重构了代码:
sub getColumns {
open my $input, '<', $ETLSplitter::configFile
or die "Error opening '$ETLSpliter::configFile': $!";
my $cols;
while( my $conline = <$input> ) {
chomp $conline;
my @values = split (/=>/, $conline);
if ($ETLSplitter::name =~ $values[0] ) {
$cols = $values[1];
last;
}
}
if($cols) {
@ETLSplitter::columns = split (':', $cols);
}
else {
die("$ETLSplitter::name is not specified in the config file");
}
}
这段代码总是死在这里die("$ETLSplitter::name is not specified in the config file");。
另一个线索是,如果我将 split (':', $cols); 更改为 split (/:/, $cols); 我会收到此错误。
perl -wle "
use modules::ETLSplitter;
\$test = ETLSplitter->new('cpr_operator_metric_actual_d2', 'frame/');
\$test->prepareCSV();"
syntax error at modules/ETLSplitter.pm line 154, near "}continue"
Compilation failed in require at -e line 2.
BEGIN failed--compilation aborted at -e line 2.
【问题讨论】:
-
如果最后去掉不必要的“
next;”还会出现这种情况吗? -
当我输入 split() 中使用的 / 字符时,它似乎会中断
-
是的,它仍然存在。即使没有下一个!
-
split 的第一个参数是一个正则表达式。如果使用“/”作为分隔符,则需要转义模式中出现的任何字面值。或者,您可以使用其他分隔符,例如“m!pattern!”
-
您能告诉我们您是如何确定您的代码“卡住”的吗?
标签: perl split readline while-loop