Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 958
thisismyrobot Avatar asked Oct 14 '13 03:10

thisismyrobot


People also ask

What does=~ do in perl?

The operator =~ associates the string with the regex match and produces a true value if the regex matched, or false if the regex did not match. In our case, World matches the second word in "Hello World" , so the expression is true.

What is the difference between -> and => in Perl?

The former is a function call. The latter is a method call.

What is the use of symbol in perl?

Perl uses the "percent" symbol and curly braces with respect to the name of an associative array as a whole, whereas individual elements within an array are referred to as scalars and the index is still placed in curly braces.


1 Answers

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.

like image 109
Keith Thompson Avatar answered Oct 01 '22 12:10

Keith Thompson