in reply to dynamically loading modules/maintaining dev v. prod modules

You can push a sub onto @INC, not just a string. Do that with use lib. When it's called, it can examine the SCRIPT_NAME and do any complex searching logic as desired.

—John

  • Comment on Re: dynamically loading modules/maintaining dev v. prod modules

Replies are listed 'Best First'.
Re^2: dynamically loading modules/maintaining dev v. prod modules
by Random_Walk (Prior) on May 29, 2006 at 11:26 UTC

    This sounds interesting if a little obfu-ish. Sadly I can not get a sub put on @INC to execute

    > perl -mlib="sub{\$x=10}" -le'BEGIN{print "x=",$x++};\ use FindBin;\ print "x=$x"; print join $/,@INC' x=0 x=1 sub{$x=10} /local/lib/perl /usr/local/lib/perl5 /usr/opt/perl5/lib/5.8.0/aix-thread-multi /usr/opt/perl5/lib/5.8.0 /usr/opt/perl5/lib/site_perl/5.8.0/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.0 /usr/opt/perl5/lib/site_perl .
    I expected to see x=10 after the use FindBin had run down the @INC path. What do I miss ?

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
      You added a string to the list. The string happened to contain Perl syntax rather than a directory name.

      You have to use a ref to a sub, not a string to be evaled.

      sub x { print "I'm here! [@_]\n" }; use lib \&x; use FindBin; print "done.\n";
      —John

        Nice trick, thanks for the help.

        Cheers,
        R.

        Pereant, qui ante nos nostra dixerunt!