Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Setting environment!!

by vnpandey (Scribe)
on Jul 03, 2000 at 21:57 UTC ( [id://20905]=perlquestion: print w/replies, xml ) Need Help??

vnpandey has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, Please help me in this simple task.i want to set the environment in which my perl programme should run through the perl programme itself. actually I type on the unix commond prompt setenv PERL5LIB /tmp_mnt/usr4/mrt/vinayPandey/lib/perl5/ which works...i.e. connectts the pgplot module etc.. How to do the same using the programme itself... thanks, VNPandey

Replies are listed 'Best First'.
Re: Setting environment!!
by ZZamboni (Curate) on Jul 03, 2000 at 22:05 UTC
    If what you want is to add directories to Perl's search path, you can use the use lib pragma:
    use lib qw(/your/dir1 /your/dir2);
    You could also manually insert the directory into @INC:
    push @INC, qw(/your/dir1 /your/dir2);
    I believe these two approaches are functionally identical, but someone may correct me about that.

    --ZZamboni

      Pretty close. The lib pragma will muck with @INC at compile time, but pushing like that isn't until runtime. For these two to be basically functionally identical, you would want to wrap the push in a BEGIN block:

      <CODE> BEGIN { push @INC, '/your/path'; } <CODE>

      Cheers,
      KM

Re: Setting environment!!
by KM (Priest) on Jul 03, 2000 at 22:12 UTC
    If you are wanting to add a directory to the include paths for modules you can:

    use lib qw(/your/path); use YourModule;

    The lib pragma will basically add that directory to @INC so you can include modules from that directory. If you want to set that env variable from within the script you can:

    BEGIN { $ENV{PERL5LIB} = "/foo"; }

    Cheers,
    KM

Re: Setting environment!!
by i43s (Novice) on Jul 03, 2000 at 22:25 UTC
    No one ( accept KM, but I think too much information sucks for newbies, so this node answers the question only )has addressed the fact that you want to set the environment variable... give the man what he wants!
    $ENV{PERL5LIB} = '/foo';
    Notice that I didn't do this within BEGIN because you may also want to include other things like CGI.pm and that will break if you set the environment BEFORE you include your packages.

    i_had_a_little_trouble_so_i_came_up_with_this

      If you truly wanted to give the man what he wants you would have done it in BEGIN because he currently sets the environment variable before his program runs, so to mimic this behavior, you would want to set it as soon as possible.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://20905]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found