in reply to newbie question: can't use my own lib in crob job

You could try:
use File::Basename; my $cwd = dirname $0; my $libpath = $cwd."/lib"; require "$libpath/My/Ownmodule.pm";
I'd have to do some research to figure out how Perl handles a "BEGIN" block in relation to "use" for loading modules. (Others here presumably know this by heart and can point to relevant nodes at the monastery). But based on the evidence in your post, I'd say that it's trying to run your BEGIN block before it has loaded File::Basename. (Maybe putting "require File::Basename;" inside the BEGIN block would solve the problem too.)

In any case, the approach shown above would avoid the issue, by using "require" to load your personal module from the intended path, and this is a run-time operation as opposed to a compile-time issue (or something to that effect).

Replies are listed 'Best First'.
Re: Re: newbie question: can't use my own lib in crob job
by iwanthome (Beadle) on Mar 30, 2004 at 02:47 UTC
    I try
    use File::Basename; my $cwd = dirname $0; my $libpath = $cwd."/lib"; require "$libpath/My/Ownmodule.pm";

    it is work normally. And putting "require File::Basename;" inside the BEGIN block can't solve the problem

    What is the difference between "require" and "use" ? Are there any disadvantage to use "require" to replace "use" ?

    I am in doubt whether there are any other method can make me to use  "use lib "xxxx"

    thanks!

      What is the difference between "require" and "use" ? Are there any disadvantage to use "require" to replace "use" ?
      perldoc -f use
      perldoc -f require

      I am in doubt whether there are any other method can make me to use "use lib "xxxx"
      Sorry, can you translate that to English?

        I am so sorry because my native language is not English.So I can't express my question exactly.

        My question is : is it possible that use "use lib" in my cron job?

        I don't know whether I express clearly.

        thanks!

        I am so sorry English is not my native language.So I can't express my question exactly.

        My question is:

        How can I use use lib "xxx/mylib" in my script if I don't use require "xxx/mylib/sss.pm"? I just want to know whether it is possible .

        thanks!