A Perl prototype is only marginally useful.
There is no "type checking".
One thing that a prototype can do is to allow you to call a user sub without () around the args...sort of mimicking a Perl built in function. I personally think this is a bad idea and use of prototype. I always enclose args in () for my functions.
Play with the below code which just shows a simple scenario with $ representing a scalar value.
#!/usr/bin/perl -w use strict; some_sub(1,2); #called too early warning error #but note that the code still runs! sub some_sub($$) #this sub requires 2 scalars { my ($a,$b) = @_; print "$a,$b\n"; } some_sub 6,8; #ok,now this is just fine some_sub 10,11,12; #too many argument error __END__ main::some_sub() called too early to check prototype at C:\TEMP\perl33 +.pl line 6. 1,2 if you reverse order or add proto above call: sub some_sub($$); some_sub(1,2); sub some_sub($$) { my ($a,$b) = @_; print "$a,$b\n"; } Perl will be happy, but to what effect?
In reply to Re: subroutine prototype in Perl
by Marshall
in thread subroutine prototype in Perl
by pavunkumar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |