in reply to Perl Module

That's a prototype which means Report takes one or two scalars, the semicolon separates required from optional arguments. Prototypes do cool things like adding new syntax to Perl and compile-time checking of parameter lists.

HTH, SSF

Replies are listed 'Best First'.
Re^2: Perl Module
by CountZero (Bishop) on Dec 31, 2008 at 06:02 UTC
    ... and are best left alone, unless you know what you are doing.

    One thing they DO NOT do is compile-time (or even run-time) checking of the arguments in the argument-list.

    Consider the following:

    sub test_noproto {print shift;}; sub test_proto ($) {print shift;}; $scalar = 'A'; @array = qw /X Y Z/; %hash = ('key', 'value'); test_noproto($scalar); # gives as expected: A test_noproto(@array); # gives as expected: X test_noproto(%hash); # gives as expected: key test_proto($scalar); # gives as expected: A test_proto(@array); # gives: 3 Did you expect that? test_proto(%hash); # gives: 1/8 Did you expect that?
    In some way (but not in others) one can say that the $ prototype magically causes the argument to the sub to be evaluated in scalar context. This all happens silently without any warning or error to the user. Saying (as perlsub does) "Perl supports a very limited kind of compile-time argument checking using function prototyping." is misleading to the unwary.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      actually test_proto(@array); was predictable , it's test_proto(%hash); that was not , is there any explanation of "1/8" value or is it just sci-fi ? also,is there any way of using parameters to functions as you do in C or C++ ? I mean you just write down the prototype and the argument names are implicitly taken to be variables which have the scope of the function to which they are arguments of ?
        If you know how (Perl-)prototypes work, it is indeed predictable, but most think the Perl-prototypes work as do prototypes in languages such as C and then they are unpleasantly surprised. This really is one of the (few) dark corners of Perl IMHO.

        All parameter passing in and out of functions or subs in Perl is done by passing in or out a flat list. There is no standard mechanism to do what you describe, although I find the following template comes close:

        sub my_subroutine { my ($required_parameter_1, $required_paramater_2, @optional_parame +ters) = @_; }
        Of course you would use more meaningful variable names in a real situation.

        The '1/8' is the value of a hash in a scalar context. It means '1 bin out of 8 possible bins are being used'. 'Bins' are what is being used internally by a hash to store the keys and values. I have never seen any practical use for this information.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^2: Perl Module
by tilly (Archbishop) on Dec 31, 2008 at 07:57 UTC
    I would describe it rather differently. I would say that prototypes give people new ways of creating bugs while being mislead into thinking that they are doing something that is potentially good.