Hi list,
I want to use the Env::Sourced module for setting some environment
variables depending on the Oracle version of a certain database:
~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~
~ ~~ ~ ~~ ~ ~~ ~ ~
#!/usr/bin/perl -w
use strict;
use warnings;
sub fnc {
my $oraenv;
my $oratabpfad="/opt/ora/9.2.0.8";
if ($oratabpfad =~ /9.2.0.8/) {
print "--- IF ---\n";
$oraenv="/opt/data/magna/viamg1/umgebungen/config/ora9208.env";
print "OraEnv: $oraenv\n";
} else {
print "--- ELSE ---\n";
$oraenv="/opt/data/magna/viamg1/umgebungen/config/ora92.env";
print "OraEnv: $oraenv\n";
}
use Env::Sourced "$oraenv";
system 'env |grep ORA';
}
fnc ();
~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~
~ ~~ ~ ~~ ~ ~~ ~ ~
Sadly, the final "use Env::Sourced..." command does not work. I suspect
the variable to be the problem but haven't yet found a way how to pass
the value to the "use" command properly. No quotes at all or double
quotes (as in code snippet) return no error, but the variables are not
set either. Single quotes or backticks return an error, of course. But
what's left, then?
I have an additional question: I also tried a solution like this:
if (...) {
use Env::Sourced "/path/to/file.env";
} else {
use Env::Sourced "/path/to/file2.env";
}
but this didn't work correctly as well, always the second file (from the
ELSE) was sourced. Am I guessing right that the latter file was sourced
because of the ambiguous "use" although this would not come to effect
during script execution? Could someone explain to me kindly why exactly
that is so?
And, of course, if my questions should be better addressed to the owner
of the module, please give me a hint.
Regards,
Nora
|