Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange perl syntax ( $$ ) in sub routine [duplicate]

Tags:

perl

What dose the ( $$ ) do in this code. I have programmed Perl for a long time but never came across this syntax until recently when I opened a very old Perl .plx file

These rows prevent me from upgrading to a more modern Perl version.

sub help( $$ ){

}

The reason it affects me is because I get an error message stating that the help function was called before it was declared. Any idea of how I can solve this without removing the ( $$ ) block??

like image 567
Pablo Jomer Avatar asked Dec 03 '22 01:12

Pablo Jomer


2 Answers

The are called prototypes. This particular one says that the sub routine expects to be called with exactly 2 scalar variables. Although prototypes are sometimes useful, mostly they are not.

If you can drop them depends on the rest of the code...

like image 119
pavel Avatar answered Dec 05 '22 13:12

pavel


That's a function prototype, which is used to specify the number and types of arguments that the subroutine takes. See the documentation.

Since it's in the current documentation, I don't see why it's preventing you from upgrading.

Is the error you're getting help called too early to check prototype? Here's the explanation from the perldiag documentation:

(W prototype) You've called a function that has a prototype before the parser saw a definition or declaration for it, and Perl could not check that the call conforms to the prototype. You need to either add an early prototype declaration for the subroutine in question, or move the subroutine definition ahead of the call to get proper prototype checking. Alternatively, if you are certain that you're calling the function correctly, you may put an ampersand before the name to avoid the warning. See perlsub.

like image 29
Barmar Avatar answered Dec 05 '22 13:12

Barmar