There are other ways, but they all have serious problems. Modules are the way to go and they don't have to be very complex. Here is the basic template:
package Mod;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw(
always_exported
);
our @EXPORT_OK = qw(
exported_on_request
also_exported_on_request
);
sub always_exported { print "Hi\n" }
sub exported_on_request { print "Hello\n" }
sub also_exported_on_request { print "hello world\n" }
1;
Create a directory, for example /home/user/perllib. Put this code in a file with a name Mod.pmin this directory. You can use the module as follows:
use strict;
use warnings;
use lib '/home/user/perllib';
use Mod qw/exported_on_request/;
always_exported();
exported_on_request();
, . , , . :: (, File::Find), /home/user/perllib. :: a /, My::Neat::Module /home/user/perllib/My/Neat/Module.pm. perldoc perlmod Exporter perldoc Exporter