Hello, I'm a PHP programmer and am working with a Perl script that somebody already wrote.

There is defined subroutine that is called "sub_add".
I'm reading few Perl books and to invoke subroutine do:
&sub_add(); or sub_add();

This subroutine doesn't return anything.

However, this script written like code below.
I don't understand what it's doing.

Please someone help.
Thank you.
sub sub_add($);
sub sub_add($) { here

Open in new window

Who is Participating?
clockwatcherConnect With a Mentor Commented:
Not sure what your question really is, but

   sub sub_add($);  # this is a forward declaration for a subroutine called sub_add that expects a scalar argument

   sub_add("hello");   # this calls the sub_add subroutine passing it the argument hello

   sub sub_add($) {  # this is the definition of the subroutine sub_add

      .... code here

mjcoyneConnect With a Mentor Commented:
The first is a forward declaration of the subroutine with a prototype.  Prototyping is a method to force the Perl interpreter to check that the right types of parameters are supplied to a subfunction, otherwise they just get a flattened list of scalar values.

See "Protoypes" in perlsub (e.g. at
eb110kAuthor Commented:
Thank you for your help.
All Courses

From novice to tech pro — start learning today.