0

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 ..

mpapec
  • 50,217
  • 8
  • 67
  • 127
user2234234
  • 349
  • 1
  • 7
  • 18

1 Answers1

2

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);
mpapec
  • 50,217
  • 8
  • 67
  • 127