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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.