Possible Duplicate:
What does the function declaration “sub function($$)” mean?
sub t(&@) {
print @_;
}
t {print 1};
I tried to change &@ to &$ and it will fail.
What's the lingo for it so that I can search?
Possible Duplicate:
What does the function declaration “sub function($$)” mean?
sub t(&@) {
print @_;
}
t {print 1};
I tried to change &@ to &$ and it will fail.
What's the lingo for it so that I can search?
&@ is a subroutine prototype. This lets you create syntax similar to the builtin grep function (accepts a BLOCK and then a LIST). The LIST can even be the empty list: ().
&$ when used will force the second argument (which is mandatory) to be evaluated in scalar context. Since there is no second argument in t {print 1}; it will fail to compile.
Read more about subroutine prototypes at: perldoc perlsub.
I'm not quite clear on what you want the code to do, but you are creating a prototype for your sub, see the perldocs. The & means the sub t takes a block as the first argument and the @ means the rest of the arguments are an array.
When you call your function, you are passing it one argument, the block {print 1} and that is what you are then printing out - the CODE reference as a string. The reason &$ fails is you are not passing a second argument. That is fine for &@ as the second argument is the empty array.