perl - perl 中的@$ 是什么?

标签 perl exception-handling sigils

我遇到了这个,希望它是 $@ 的拼写错误:

use strict;
use warnings;

eval {
  my $error = Not::Here->new();
};

warn @$;

令我惊讶的是它输出了这个:

Can't locate object method "new" via package "Not::Here" (perhaps you forgot to load "Not::Here"?) at dollar_array.pl line 6. ...caught at dollar_array.pl line 9.



我找不到有关 @$ 的任何信息,并且它没有在 perlvar 上列出,也不在 eval

由于输出显示 caught at ... ,看来这是perl的异常处理中的东西。

最佳答案

@$在 Perl 中(还)没有意义。它的存在是因为 $$存在(对于每个特殊变量“sigil-char”,所有其他“another_sigil-char”变量都存在)。因此,warn没有参数 - 您可以仅使用 warn; 来验证这一点- 你会得到相同的输出。

现在,让我们阅读 warn 的文档:

If the output is empty and $@ already contains a value (typically from a previous eval) that value is used after appending "\t...caught" to $@. This is useful for staying almost, but not entirely similar to die.


$@包含来自 eval 的异常,所以行为是预期的。

关于perl - perl 中的@$ 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955802/

相关文章:

c++ - Qt平台如何独立捕获异常?

variables - perl6 : do I need the @-sigil for userdefined variables?

bash - 在 perl 中通过 ssh 将外部命令错误定向到文件

linux - perl 脚本添加额外的大括号

html - 使用 mechanize::phantomjs 选择单选按钮时出现 "element does not exist in cache"错误

perl - perl 中的继承和默认构造函数

error-handling - 有什么方法可以处理和返回领域驱动设计实体和聚合根中的错误(非异常和异常)?

c++ - 比 C++ 中的异常处理更好的语言特性?

jquery - "jQuery(function ($) {})"这是什么意思?