Example that I saw in a page is as follows
sub f($$); //Function declaration.
@a = (5, 9);
Now we will see what will happen for different calls.
&f; The & bypasses subroutine prototypes, so the compiler won't complain about the subroutine call. The call also has no argument list, so it is called with its caller's @_.
&f(); f is called with an empty argument list. The & causes the subroutine prototypes to be bypassed.
f(); It won't compile because the prototype mismatch.
f; It won't compile again.
f(@a); It won't compile because the argument expected is scalars but passed is an array.
f(@a, @a); This will compile. The compiler interprets the @a in scalar context, so it will pass the no:of:elements in the array to the function.
&f(@a); This also compiles. The & disables prototype checking, so @a becomes the @_ of the subroutine. This is equivalent to f(5,9).
In reply to Re: Perl Module
by lakshmananindia
in thread Perl Module
by pparesh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |