H
Helmut Richter
It was my understanding that importing variables from packages is only
needed for using them by their unqualified names, but this seems to be
wrong. Here is the source:
There is a module CGI_Fiona.pm starting with the following code:
---- start code example ----
package CGI_Fiona;
use strict;
use vars qw(@ISA @EXPORT);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(script_begin script_end);
my ($postlude, $included_file);
sub script_begin {
...
$included_file = "/some/filename";
...
}
---- end code example ----
The package is used by a script include_file.pl starting with the follong
code:
---- start code example ----
#! /usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Encode;
use lib '/info/www/PERLLIB/';
use CGI_Fiona;
my ($text, $textlength, $outtext);
script_begin();
open (INCLUDED, "<$CGI_Fiona::included_file") || die "unable to open
\"$CGI_Fiona::included_file\": $!\n";
---- end code example ----
Everything compiles fine, but on execution the variable
$CGI_Fiona::included_file has no value inside include_file.pl although
the variable $included_file (which I assumed to be the same variable) has
been set in script_begin() inside CGI_Fiona.pm .
I could try to repair the situation by also exporting the variable with
the same means as the subs, but first I want to understand why this is
necessary. A fully qualified variable should be visible everywhere,
shouldn't it?
needed for using them by their unqualified names, but this seems to be
wrong. Here is the source:
There is a module CGI_Fiona.pm starting with the following code:
---- start code example ----
package CGI_Fiona;
use strict;
use vars qw(@ISA @EXPORT);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(script_begin script_end);
my ($postlude, $included_file);
sub script_begin {
...
$included_file = "/some/filename";
...
}
---- end code example ----
The package is used by a script include_file.pl starting with the follong
code:
---- start code example ----
#! /usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Encode;
use lib '/info/www/PERLLIB/';
use CGI_Fiona;
my ($text, $textlength, $outtext);
script_begin();
open (INCLUDED, "<$CGI_Fiona::included_file") || die "unable to open
\"$CGI_Fiona::included_file\": $!\n";
---- end code example ----
Everything compiles fine, but on execution the variable
$CGI_Fiona::included_file has no value inside include_file.pl although
the variable $included_file (which I assumed to be the same variable) has
been set in script_begin() inside CGI_Fiona.pm .
I could try to repair the situation by also exporting the variable with
the same means as the subs, but first I want to understand why this is
necessary. A fully qualified variable should be visible everywhere,
shouldn't it?