I have seen usage of $
in subroutine definition somewhere. To learn more about it, I created various cases with a simple subroutine, and came to know that it's used for defining subroutines with exact signatures.
Can anyone please confirm:
- Whether I'm right? I mean whether it's used for this purpose?
- Whether it has any other uses?
- Is there any other way to access those parameters inside subroutine, other than using
my $param1 = shift;
ormy (@params) = @_
?
use strict;
use warnings;
# just a testing function
sub show($$){
print "Inside show";
}
show(1, 1); # works fine
show(1); # gives compilation error
# Not enough arguments for main::show at test.pl line 8, near "1)"
# Execution of test.pl aborted due to compilation errors.
show(1, 1, 1); # gives compilation error
# Too many arguments for main::show at test.pl line 8, near "1)"
# Execution of test.pl aborted due to compilation errors.