F
Florence HENRY
Hello,
I do not manage to propagate my global variables through all the subroutines
of my program.
I define some global variables using a module :
### pdsdb_var.pm
package pdsdb_var;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(@columns_char @columns_num);
@columns_char = (1, 2, 3, 4, 5);
@columns_num = ("blah", "blah", "blah");
1;
__END__
### end of pdsdb_var.pm
And I use them in the main program :
#!/usr/bin/perl
use pdsdb_var qw(@columns_char @columns_num);
print @columns_char . "\n";
print @columns_num . "\n";
### end of main
Until here, it works nice. My problem is that I cannot use those global
variables from a subroutine that is defined in another package :
### pdsdb_sub.pm
package pdsdb_sub;
sub main:
rintVar {
print @columns_char . "\n";
print @columns_num . "\n";
return;
}
1;
__END__
### end of pdsdb_sub.pm
If I use this function from my main program :
#!/usr/bin/perl
use pdsdb_var qw(@columns_char @columns_num);
use pdsdb_sub;
print @columns_char . "\n";
print @columns_num . "\n";
main:
rintVar();
### end of main
the program prints :
5
3
0
0
which means that my global variables are not defined within pdsdb_sub.pm
How could I manage to propagate my global variables within all my
subroutines ?
I precise that I cannot write :
use pdsdb_var qw(@columns_char @columns_num);
within pdsdb_sub.pm because my real problem is a little more complicated
than that :
* I have several programs, and some of them share the same data (same name,
same content), and some just share the data type (same name but content
differs), so I defined several modules pdsdb_var1.pm, pdsdb_var2.pm, ...
which I include where needed.
* All the programs use the same functions defined in
pdsdb_sub.pm (so I have to use pdsdb_sub in each one). These functions are
supposed to use the variables defined in pdsdb_varX.pm, which content
differs following the main calling program.
Thanks for any help.
I do not manage to propagate my global variables through all the subroutines
of my program.
I define some global variables using a module :
### pdsdb_var.pm
package pdsdb_var;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(@columns_char @columns_num);
@columns_char = (1, 2, 3, 4, 5);
@columns_num = ("blah", "blah", "blah");
1;
__END__
### end of pdsdb_var.pm
And I use them in the main program :
#!/usr/bin/perl
use pdsdb_var qw(@columns_char @columns_num);
print @columns_char . "\n";
print @columns_num . "\n";
### end of main
Until here, it works nice. My problem is that I cannot use those global
variables from a subroutine that is defined in another package :
### pdsdb_sub.pm
package pdsdb_sub;
sub main:
print @columns_char . "\n";
print @columns_num . "\n";
return;
}
1;
__END__
### end of pdsdb_sub.pm
If I use this function from my main program :
#!/usr/bin/perl
use pdsdb_var qw(@columns_char @columns_num);
use pdsdb_sub;
print @columns_char . "\n";
print @columns_num . "\n";
main:
### end of main
the program prints :
5
3
0
0
which means that my global variables are not defined within pdsdb_sub.pm
How could I manage to propagate my global variables within all my
subroutines ?
I precise that I cannot write :
use pdsdb_var qw(@columns_char @columns_num);
within pdsdb_sub.pm because my real problem is a little more complicated
than that :
* I have several programs, and some of them share the same data (same name,
same content), and some just share the data type (same name but content
differs), so I defined several modules pdsdb_var1.pm, pdsdb_var2.pm, ...
which I include where needed.
* All the programs use the same functions defined in
pdsdb_sub.pm (so I have to use pdsdb_sub in each one). These functions are
supposed to use the variables defined in pdsdb_varX.pm, which content
differs following the main calling program.
Thanks for any help.