How to include definitions from one Perl file to another?

Posted by oleg_repin on 2015-05-04 04:25

I believe this question has already been asked million times. And I spent significant time trying to find answer. No luck yet.

The simplest problem. I have some common value shared by several Perl scripts. Let it be
my $my_value = 12345;

Then in each script I would like to perform the code
print $my_value;

How to do it?

I created 'common.pl' and 'common.pm' files with the following content:
my $my_value = 12345;
1;
I also tried
our $my_value = 12345;

Then I tried to use:
do 'common.pl';
require 'common.pl';
require common;
use common;
in my 'test.pl'. Every time I just see some errors.

UPDATE
OK. I found unswer myself. Right code is following:
use lib '.';
use common;
print $my_value;