所以我的问题是基于这个问题: 如何将子程序作为参数传递给另一个子程序
问题是:我可以将参数/参数传递给子程序(它本身也是一个参数)吗?
sub question {
print "question the term";
return 1;
}
my $question_subref = \&question;
answer($question_subref);
sub answer {
my $question_subref = shift;
print "subroutine question is used as parameters";
# call it using arrow operator if needed
$question_subref -> ($PassSomethingHere,$SomethingElse);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
是否有可能做到这一点?
$ question_subref - >($ PassSomethingHere,$ SomethingElse);
下面是实际的代码:
my $SelectResults = sub {
my @results;
$sql = $_[0];
$sth = $_[1];
$sql =~ s/select/SELECT/gi;
if(StrContains($sql, "SELECT"))
{
@results= $sth->fetchrow_array();
foreach my $tab …Run Code Online (Sandbox Code Playgroud) 通常,短路or操作符||忽略右侧或左侧评估为真.显然,我们发现了一个例外.
请查看以下内容:
if (foo == null || bar != true ? foo.Count == 0 : true)
{
}
Run Code Online (Sandbox Code Playgroud)
此代码在命令上抛出空引用异常,foo.Count因为它foo为null.当然,布尔逻辑允许这样做.但是,如果foo为null,你会期望它or会短路,甚至不评估表达式的右侧,但它仍然会这样做,并且它会引发异常.
这是我的代码或C#编译器中的错误吗?是否有一部分C#规范可以处理这种情况?