简体   繁体   中英

What is @$ in perl?

I came across this, expecting it to be a typo for $@ :

use strict;
use warnings;

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

warn @$;

And to my surprise it outputs this:

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.

I'm unable to find any information about @$ , and it's not listed on perlvar , nor in eval

Since the output show caught at ... , it seems that this is something in the exception handling of perl.

@$ has no meaning (yet) in Perl. It exists because $$ exists (for each special variable "sigil-char", all other "another_sigil-char" variables exist). Therefore, warn gets no arguments - you can verify that by using just warn; - you'll get the same output.

Now, let's read the documentation for 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 .

$@ contains the exception from the eval , so the behaviour is expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM