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

1) I have a library path set up like the following at the beginning for my .pl files. If I have a module by the same name(say MyModule.pm) present in both directories, which one will perl use?

2) Also, the approach I have taken to include perl modules, is it a good one. Are there better ways?

Thanks

BEGIN { unshift (@INC, "/common/LIBRARIES"); unshift (@INC, "/common/LIBRARIES/common"); }

Replies are listed 'Best First'.
Re: Library path question
by ikegami (Patriarch) on Apr 08, 2012 at 03:27 UTC

    1) The first one Perl finds, iterating from @INC from start to end, so /common/LIBRARIES/common/MyModule.pm

    2) Functionally perfect, so the only possible improvement is style. I'd use

    use lib "/common/LIBRARIES/common", "/common/LIBRARIES";

    But even the following would be better to me:

    BEGIN { unshift @INC, "/common/LIBRARIES/common", "/common/LIBRARIES"; }
      Thank you.