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 Atlys;
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 derby (Abbot) on Jul 08, 2003 at 19:22 UTC
    BEGIN blocks are done just then ... at the beginning. So in your example, $home is interpolated as a null string. Try:

    BEGIN { push( @INC, $ENV{HOME} . "/prod_support/scripts" ); }

    Or another (more modern) way:

    use lib "$ENV{HOME}/prod_support/scripts";

    -derby

      While use lib is nice, it doesn't push; it unshifts. There is no pragma that unshifts, AFAIK. So the push in BEGIN is pretty much the only option.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        Sure. I assumed (wrongly probably) that in this particular instance the poster didn't really care about controlling the loading (ala @INC positioning) but was more concerned about getting the unique project specific stuff into @INC.

        -derby