#Package.pm package My::Package; use strict; #can use strict and warnings as usual now as well without +any warnings use warnings; use Exporter qw(import); our @EXPORT = qw(print_lines test test_2); #just add in function names + as you make them our %EXPORT_TAGS = (all => \@EXPORT); sub print_lines{ my ($input) = shift; while(<$input>){ print; } close($input); } sub test{ my ($input) = shift; print $input; } sub test_2{ my ($input) = shift; print $input; }
And here is the script calling it
#script.pl use strict; use warnings; use My::Package qw(:all); open (my $file, '<', shift); print_lines($file); test("hello world\n"); test_2("hello this is dog"); # i love this meme lol
That ":all" is what i was originally shooting for. Though I also figured out you could just require My::Package; and then just call it in the script with use My::Package; and do not have to specify any functions. Anyways, thanks for the help fellers :)
UPDATE: Also I wanted to ask, if I use strict and warnings in the main script, is that in the modules scope as well, or do I need to use strict and warnings in the module as well? Also IF strict and warnings are in the same scope, is it just for the functions/subs or the whole module?
In reply to Re: Is this safe to export and import functions this way?
by james28909
in thread Is this safe to export and import functions this way?
by james28909
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |