这已被转移到一个测试用例在这里.
我想从2个子程序返回数组(必须是引用),但是用作条件语句的正则表达式并不像我希望的那样工作.我试过用一个,但我觉得这会更容易.
需要明确的是,我的目标是有排序的匹配(阵列@all_matches),然后添加另一个阵列(@all_pronoun_matches)排序方式相同,但在添加结束.
这是@pronoun_matches子程序:
my ($line, $verbform, $chapternumber, $sentencenumber, $sentence) = @_;
my @matches;
my @pronoun_matches;
return unless ($line =~ /(\w+)\((\w+)\-\d+\,\s(\w+)\-\d+\)/); #2nd repeat check
$grammar_relation = $1;
$argument1 = $2;
$argument2 = $3;
return if (($argument1 =~ /^$argument2/i)||($argument2 =~ /^$argument1/i));
foreach my $pronoun (@stopListNoun)
{
if ((lc $pronoun eq lc $argument1) || (lc $pronoun eq lc $argument2))
{
push (@pronoun_matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument2, $argument1) if ($argument2 =~ /$verbform/i);
push (@pronoun_matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2) if ($argument1 =~ /$verbform/i);
}
else
{return}
}
return (\@pronoun_matches);
Run Code Online (Sandbox Code Playgroud)
它@matches有一个非常相似的子程序,除了这个:
foreach my $pronoun (@stopListNoun) #Just a list of words
{
return if ((lc $pronoun eq lc $argument1) || (lc $pronoun eq lc $argument2));
}
push (@matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument2, $argument1) if ($argument2 =~ /$verbform/i); ##USED TO BE 'eq', but that prevented protective from showing
push (@matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2) if ($argument1 =~ /$verbform/i);
return \@matches;
Run Code Online (Sandbox Code Playgroud)
这称为:
my $matches;
my $pronoun_matches;
$matches = &dependency_checks($lines[$l], $verbform, $chapternumber, $sentencenumber, $sentence);
$pronoun_matches = &pronoun_dependency_checks($lines[$l], $verbform, $chapternumber, $sentencenumber, $sentence);
push @all_matches, $matches if ($matches);
push @all_pronoun_matches, $pronoun_matches if ($pronoun_matches);
Run Code Online (Sandbox Code Playgroud)
要在使用哈希值排序后发送到打印部分,我想使用:
@all_matches = (@all_matches, @all_pronoun_matches);但是,@all_pronoun_matches有0个匹配(或者它们在某处被过滤).
为什么@all_pronoun_matches有未初始化的值?经过一些测试,我发现匹配永远不会通过条件语句,但它与@matches子例程中的匹配相同!
最初,我只是想删除代词并且它工作正常,所以我知道条件有效:
foreach my $pronoun (@stopListNoun)
{
return if ((lc $pronoun eq lc $argument1) || (lc $pronoun eq lc $argument2));
}
Run Code Online (Sandbox Code Playgroud)
我尝试在foreach中使用if-else并组合子程序,但是所有匹配(包括代词)都进入了@all_matches尽管被正确调用(此方法之前发布在此处).
如果我的意图或问题有任何不清楚的地方,请告诉我.
@all_matches = @matches, @all_pronoun_matches;
Run Code Online (Sandbox Code Playgroud)
应该
@all_matches = ( @matches, @all_pronoun_matches );
Run Code Online (Sandbox Code Playgroud)
,优先级低于=
如果启用了警告,你会得到一个在无效的情况下没用使用变量的警告,提醒您@all_pronoun_matches没有成为任务的一部分.
| 归档时间: |
|
| 查看次数: |
113 次 |
| 最近记录: |