Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

newbie question:operation @INC

by iwanthome (Beadle)
on Mar 30, 2004 at 03:16 UTC ( [id://340846]=perlquestion: print w/replies, xml ) Need Help??

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

I use following script add my own lib directory to @INC,
#!/usr/bin/perl unshift (@INC,"/data/zht/perl"); foreach(@INC) { print; }

But after scirpt running ,I use "perl -V" to display @INC,why I can't see my lib directory ?

If my script can running concurrent,will it add duplicate my lib directory to @INC ?

thanks!

Replies are listed 'Best First'.
Re: newbie question:operation @INC
by pbeckingham (Parson) on Mar 30, 2004 at 03:20 UTC

    Using perl -V shows the @INC compiled into your perl. You are making a runtime modification to @INC. The latter does not affect the former. Or in other words, your scripts must modify @INC on every invocation.

Re: newbie question:operation @INC
by jZed (Prior) on Mar 30, 2004 at 03:21 UTC
    Your code only modifies @INC for the duration of your script. To modify @INC in your environment, set the PERL5LIB environment variable in your shell, not in a script.
Re: newbie question:operation @INC
by Fletch (Bishop) on Mar 30, 2004 at 03:23 UTC

    a) changing @INC at runtime won't work for modules (subsequent evals or requires will see the change, but not any uses); b) what you've done in no way modifies @INC for any subsequent invocations of perl. If you want to permanently modify it you need to set PERL5LIB in the environment, use the -I command line switch each time, or recompile perl. See perldoc lib and perldoc perlrun and read carefully.

Re: newbie question:operation @INC
by MarkM (Curate) on Mar 30, 2004 at 03:20 UTC

    What do you mean 'after script running, I use "perl -V"'?

    @INC is local to the script. It doesn't affect the parent, nor is a modified @INC automatically inherited to a child process.

    If you need to modify @INC for a script that you do not wish to alter, try setting the environment variable PERL5LIB. See "perlrun" for more information.

Re: newbie question:operation @INC
by Mr. Muskrat (Canon) on Mar 30, 2004 at 03:33 UTC
    You could always see it like this:
    perl '-Mlib qw(/data/zht/perl)' -V

    update: Although, that's probably not what you really want...

Re: newbie question:operation @INC
by iwanthome (Beadle) on Mar 30, 2004 at 04:07 UTC
    thanks for everyone! I got it!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found