推荐答案
更新:
很简单,实际上,您将connect调用返回的句柄分配给$l_dbh,但是在$dbh上调用了一个方法.您必须使用严格.
Update:
Simple, really, you assign the handle returned by the connect call to $l_dbh but invoke a method on $dbh. You must use strict.
未定义数据库句柄$dbh,这意味着连接失败.您应该检查呼叫的返回值,或者在connect呼叫中指定{ RaiseError => 1}以查明原因.
The database handle $dbh is not defined which means the connection failed. You should either check return values of your calls, or specify { RaiseError => 1} in the connect call to find out the reason.
此外,没有理由为每个子调用加上&前缀:使用ConnectFailed( )代替&ConnectFailed( ),除非您知道给子调用加上&前缀的效果并希望具有这种效果.
Further, there is no reason to prefix every sub invocation with &: Use ConnectFailed( ) instead of &ConnectFailed( ), unless you know the effect of prefixing a sub invocation with & and desire to have that effect.
来自 perldoc perlsub :
可以使用显式的&前缀调用子例程.在现代Perl中,&是可选的,如果预先声明了子例程,则括号也是如此.仅在命名子例程时(例如,将其用作defined()或undef()的参数时),&不是可选的.当您要使用&$subref()或&{$subref}()结构使用子例程名称或引用进行间接子例程调用时,它也不是可选的,尽管$subref->()表示法解决了该问题.
A subroutine may be called using an explicit & prefix. The & is optional in modern Perl, as are parentheses if the subroutine has been predeclared. The & is not optional when just naming the subroutine, such as when it's used as an argument to defined() or undef(). Nor is it optional when you want to do an indirect subroutine call with a subroutine name or reference using the &$subref() or &{$subref}() constructs, although the $subref->() notation solves that problem.
...如果使用&格式调用子例程,则参数列表是可选的,如果省略,则不会为该子例程设置@_数组:调用对子例程可见. 这是新用户可能希望避免的效率机制.(强调).
... If a subroutine is called using the & form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid. (emphasis added).
更多推荐
Perl DBI错误消息:无法调用方法"selectcol
发布评论