[英]Perl DBI Constants - how to access?
The documentation for getting type info includes this piece of suggested code for getting the mapping between code and integer: 获取类型信息的文档包括以下建议代码,用于获取代码与整数之间的映射:
foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) {
printf "%s=%d\n", $_, &{"DBI::$_"};
}
But perl 5.16.2 won't allow it: 但是perl 5.16.2不允许:
Can't use string ("DBI::SQL_GUID") as a subroutine ref while "strict refs" in use
I don't know how to turn off strict refs and I suspect it wasn't the author's intention that anyone do so. 我不知道该如何关闭严格的引用,而且我怀疑任何人这样做都不是作者的意图。 How can this subroutine call be accomplished?
该子例程调用如何完成?
You can turn off strict 'refs' by doing this 您可以通过执行以下操作关闭严格的“引用”
{
no strict 'refs';
foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) {
printf "%s=%d\n", $_, &{"DBI::$_"};
}
}
Why would you put no strict 'refs';
您为什么不提出
no strict 'refs';
on the outside? 在外面? The following is more appropriate use of
no strict 'refs';
以下是对
no strict 'refs';
更适当的使用no strict 'refs';
: :
for (@{ $DBI::EXPORT_TAGS{sql_types} }) {
no strict 'refs';
printf "%s=%d\n", $_, &{"DBI::$_"};
}
(And don't say anything about jmcneirney's being a microsecond faster because that would be wrong.) (也不要说jmcneirney快一微秒,因为那是错误的。)
Or, since \\&
isn't subject to a strict refs check, 或者,由于
\\&
不受严格的引用检查,
for (@{ $DBI::EXPORT_TAGS{sql_types} }) {
my $ref = \&{"DBI::$_"};
printf "%s=%d\n", $_, $ref->();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.