Reputation: 349
how can I use a subroutine in a required file, when the subroutien has to get variables:
file.pl:
...
sub func{
my ($var) = @_;
..
}
main.pl:
..
require "file.pl";
func(1);
..
this is not working for me, I'm getting an error says Undefined subroutine &main::func
..
Upvotes: 0
Views: 90
Reputation: 50637
Perl was telling you that no main::func
exists (main
is default package), so
you need to prefix your function with qualified package name,
require "file.pl";
Naming::func(1);
Upvotes: 2