in reply to Perl Module
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Module
by CountZero (Bishop) on Dec 31, 2008 at 10:30 UTC | |
by cdarke (Prior) on Dec 31, 2008 at 11:33 UTC | |
by CountZero (Bishop) on Jan 01, 2009 at 22:08 UTC |