Reputation: 375
which is a better approach invoking perl subroutines using a '&' or something like below
checkValueExists($value);
sub checkValueExists{
my $value=@_;
#further code
}
Second approach Invoke sub using
&checkValueExists($value);
Upvotes: 0
Views: 72
Reputation: 3805
More than you ever needed to know about Perl subroutines is in the perlsub man page, but the simple answer is that &foo
is a Perl4-ism, and is rarely used in Perl5.
As another commenter has noted, it disables prototypes. &
is also used if you need to take a reference to a subroutine \&foo
, or if you need to call such a reference &$foo
. These are more advanced Perl features that you're not likely to need yet if you're asking such a relatively basic question.
Upvotes: 1
Reputation: 386541
&
is an instruction to ignore the prototype. It's not likely to be something you'll ever need to do. It makes no sense to use it here as the sub has no prototype, and there would be no reason to override it if it had one.
Upvotes: 5