M
Michael Yang
I want to access one global variable saved in the main script from
another one module. Here is what it looks like:
A.pl: the main program, with one variable, e.g., $var, declared as
global.
#!/usr/bin/perl
use strict;
use warnings;
use B;
our $var = "hello";
testB();
B.pm: the module file, from which I want to access the $var variable
in A.pl
#!/usr/bin/perl
package B;
use strict;
use warnings;
require "A.pl"; ###########Actually I don't like this way, due
to some problem
sub testB{
print "In B.pm, the variable is $var\n";
############Here I want the $var value in A.pl be accessible.
}
Is there a way doing this like in C language, we just need to declare
it in B.pm, that the $var has been defined elsewhere, so it won't be
checked during compile time but in runtime.
The reason I don't want use 'require' statement, is the A.pl will be
evaluated. But I only need it to check the declaration and assignment
of the variable $var.
Thanks all.
another one module. Here is what it looks like:
A.pl: the main program, with one variable, e.g., $var, declared as
global.
#!/usr/bin/perl
use strict;
use warnings;
use B;
our $var = "hello";
testB();
B.pm: the module file, from which I want to access the $var variable
in A.pl
#!/usr/bin/perl
package B;
use strict;
use warnings;
require "A.pl"; ###########Actually I don't like this way, due
to some problem
sub testB{
print "In B.pm, the variable is $var\n";
############Here I want the $var value in A.pl be accessible.
}
Is there a way doing this like in C language, we just need to declare
it in B.pm, that the $var has been defined elsewhere, so it won't be
checked during compile time but in runtime.
The reason I don't want use 'require' statement, is the A.pl will be
evaluated. But I only need it to check the declaration and assignment
of the variable $var.
Thanks all.