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

I am having problem doing a push into @INC. The code
snippet is --
#!/apps/bin/perl $home = $ENV{"HOME"}; # User defined library BEGIN { push @INC, "$home/prod_support/scripts" }; use myLib;
Getting the following error message -
can't open open $home/prod_support/scripts/support.env for reading No such file or directory at myLib.pm line 134.
Any idea how I can resolve this problem?

Replies are listed 'Best First'.
Re: Problem pushing into @INC
by dragonchild (Archbishop) on Jul 08, 2003 at 19:23 UTC
    1. use lib is better.
    2. BEGIN blocks execute before anything else, including code above it.
    use lib "$ENV{HOME}/prod_support/scripts"; use myLib; #### Or ... BEGIN { $home = $ENV{HOME}; push @INC, "$home/prod_support/scripts"; } use myLib;
    On a separate note, you should be using strict and warnings.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      While use lib is fine, it's not a push, it's an unshift. This may or may not be important to the final task.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

Re: Problem pushing into @INC
by nite_man (Deacon) on Jul 09, 2003 at 06:24 UTC
    You can define a path to your library using .bash_profile for standalon scripts and .htaccess for web based scripts:
    in the .bash_profile: export PERL5LIB='~/prod_support/scripts' in the .htaccess: PerlSetEnv PERL5LIB ~/prod_support/scripts
          
    --------------------------------
    SV* sv_bless(SV* sv, HV* stash);