Perl DBI错误消息:无法调用方法"selectcol

编程入门 行业动态 更新时间:2024-10-24 02:02:02
本文介绍了Perl DBI错误消息:无法调用方法"selectcol_arrayref";在一个未定义的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 my $dblinks = ''; $dblinks = $dbh->selectcol_arrayref("select db_link from db_links where ticket=\'LOW\'"); my $success = 0; for my $dblink (@$dblinks) { $success = eval { my ($ret) = $dbh->selectrow_array("select 1 from " . $dbh->quote_identifier($dblink, 'SYSIBM', "SYSDUMMY1") ); $ret; }; if ($success) { &Logging (3, $I, "connect_${G_CONNECT_COUNT}", "Connect success for $dblink"); } else { # Read thru the selectcol_array, check for an oracle error $l_msg="$dblink Result doesn't match 1"; @l_errstr=(); &ConnectFailed ($p_host, $p_db, $p_ars, $p_ars_sev, $l_msg, $p_cid, @l_errstr); # Raise a Ticket with Oracle message &Logging (3, $I, "connect_${G_CONNECT_COUNT}", "Connect failed for $dblink"); } $l_dbh->commit(); $l_dbh->do(qq{alter session close database link "$dblink"}); }

推荐答案

更新:

很简单,实际上,您将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

本文发布于:2023-10-23 06:01:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   消息   方法   DBI   Perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!