in reply to How to execute/call perl module on different path ?

Perhaps with: use lib '/data/script'

(see https://metacpan.org/module/lib )

Replies are listed 'Best First'.
Re^2: How to execute/call perl module on different path ?
by thomas895 (Deacon) on Jun 06, 2012 at 18:00 UTC

    Or, alternatively:

    #!/usr/bin/perl BEGIN { push( @INC, "/data/script" ); }

    Either one works, but the first is probably preferred.

    ~Thomas~
    confess( "I offer no guarantees on my code." );

      use lib $extra is (roughly) equivalent to BEGIN { unshift @INC,$extra }, so perl searches for libraries in $extra first. Your code

      BEGIN { push( @INC, "/data/script" ); }

      makes perl search for libraries in extra last, and only if no matching libraries were found in the original @INC.

      That's hardly the same, and while it "works" in this special case, it will probably break in other situations.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Well, yeah, that is true. It is (hopefully) common knowledge that you can use any array modification technique to add your path.
        You could also add the path somewhere in the middle, if you really wanted. Or perhaps set it as the second element. Second to last, perhaps?
        It's just redundant to list all possibilities. And usually, good programmers take steps to avoid naming conflicts, regardless of where your code is stored.

        ~Thomas~
        confess( "I offer no guarantees on my code." );