What does the dollar sign mean in the brackets of the Perl routine?

I have inherited some Perl code, and sometimes I see routines defined as follows:

sub do_it($) {
    ...
}

I can not find documents that explain this. What does the dollar symbol in parentheses mean?

+4
source share
2 answers

This is a prototype subroutine .

The only one $means that sub will take only one scalar value and will interpret other types using a scalar context. For example, if you pass an array as a parameter, for example. do_it(@array), Perl will not decrypt @arrayto the list, but instead pass the length of the array to the body of the routine.

, Perl , . , Perl . & ( ), , .

- , OO Perl. , . Perl Best Practices .

+6

($) .

. PerlSub: http://perldoc.perl.org/perlsub.html#Prototypes

Prototyping is not very common these days. Best practice does not use it .

+5
source

All Articles