Could I also write

eval { use Env::Sourced "$oraenv"; } or die "Error in Eval $_";

to do the use on run time?

Greets
Christoph

Jay Savage schrieb:
On Wed, Mar 10, 2010 at 5:56 AM, HACKER Nora <nora.hac...@stgkk.at> wrote:
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;

[snip]

       use Env::Sourced "$oraenv";
       system 'env |grep ORA';
}

fnc ();
~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~ ~ ~~
~ ~~ ~ ~~ ~ ~~ ~ ~

Sadly, the final "use Env::Sourced..." command does not work. I suspect


Hi Nora,

Use has a special behavior that effectively wraps the module import in
a BEGIN block. See perldoc -f use for details.

This means that regardless of where you typed 'use Env::Sourced', the
module is being imported long before you declare $oraenv. In fact, you
should see errors about "BEGIN Failed" and "" not being exported.

You should really be using require, here, instead:

    require Env::Sourced;
    Env::Sourced->import($oraenv);

See perldoc -f require for details.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com

values of β will give rise to dom!


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

Reply via email to