简体   繁体   中英

What is the meaning of the double 'at' (@@) in Perl?

I am reviewing a proposed vendor-supplied patch to a Perl tool we use and I'm struggling to identify the reason for a particular type of change - the pre-pending of an '@' to the parameters passed to a subroutine.

For instance, a line that was:

my ($genfd) = @_;

Is now:

my ($genfd) = @@_;

Not being a Perl developer, I'm learning on the go here, but so far I understand that '@_' is the parameters supplied to the enclosing subroutine.

I also understand the assignment above (where the '$genfd' is wrapped in parentheses on the left-hand side) casts '@_' to a list and then assign the 'genfd' scalar variable to the first element of that list. This should result in the first parameter to the subroutine being stored in 'genfd'.

What I am completely stuck on is what difference the second '@' makes. I've found examples of this usage on GitHub but never with an explanation, nor can I find an explanation on any Perl references or SO. Any help would be much appreciated.

Looks like a bad patch.

@@_ is a syntax error. At least, when I have the following Perl source file:

#!/usr/bin/perl

use strict;
use warnings;

sub foo {
    my ($genfd) = @@_;
}

running perl -cw on it (with Perl 5.14.2) gives:

Bareword found where operator expected at tmp.pl line 7, near "@@_"
        (Missing operator before _?)
syntax error at tmp.pl line 7, near "@@_"
tmp.pl had compilation errors.

I haven't looked at all the examples on GitHub, but many of them are in files with a ,v suffix. That suffix is used by RCS and CVS for their internal version control files. I think the @ character has some special meaning, so it's doubled to denote a literal @ character. (Yes, it's a bit odd to have RCS or CVS internal files in a Git repository.)

Some kind of RCS or CVS interaction is the most likely explanation for the error, but there could be other causes.

You should ask the person who provided the patch.

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