Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Just looking through source code and found the line below. What is $ doing or representing?
sub head ($)

Replies are listed 'Best First'.
Re: What is inside of () on a sub call?
by Zaxo (Archbishop) on May 22, 2004 at 03:46 UTC

    A single scalar argument. That is a perl prototype for sub head, which instructs the perl compiler to count and characterize arguments.

    After Compline,
    Zaxo

      Thanks but that still is a bit confusing. It counts and characterizes arguements? Does that mean it's not looking for anything in particular? It'll accept any input?

        It will only accept a single scalar. That scalar might be a constant string, a scalar variable, or a reference to anything. Perl prototypes are not for enforcing types or informing anybody of expected content. That is a major difference with C/C++ or Java.

        Characterization only happens if your type is listed in the prototype as \$. In that case a reference to an lvalue scalar is admitted. References to hashes, arrays, code etc. are all possible.

        Update: duff++, good catch.

        After Compline,
        Zaxo

Re: What is inside of () on a sub call?
by ctilmes (Vicar) on May 22, 2004 at 09:51 UTC