Reputation: 87
I have many files. In one file ie (Lib::Utils
) I have all generic functions. I need to assign values to two variables and define the same in Lib::Utils
, and I need to export that to other files. I should not declare the variable in other files.
I tried like the below
package Lib::Utils;
require Exporter;
@ISA = qw(Exporter);
our $FAIL = 0;
our $SUCCESS = 1;
use strict;
use warnings;
use Lib::Utils;
our ($FAIL, $SUCCESS);
print("$FAIL\n$SUCCESS\n");
But I want this to export from Lib::Utils
to all other files.
Upvotes: 2
Views: 59
Reputation: 126762
There's no point in using Exporter
without populating @EXPORT
or @EXPORT_OK
.
In Lib/Utils.pm
you need to add
our @EXPORT_OK = qw/ $FAIL $SUCCESS /;
and change test.pl
like this
use strict;
use warnings 'all';
use Lib::Utils qw/ $FAIL $SUCCESS /;
print "$_\n" for $FAIL, $SUCCESS;
Upvotes: 6