Hi,

I messed around and found that
if in config i do $datadir = "/my/path/";
instead o f$datadir= "/my/path";

then in my script i do
#!/usr/bin/perl
require 'config.pl';
use $datadir."Module";

everything works again.
Thanx for the suggestion tough because i didn't know how to use BEGIN now i
do :-))))

Awards



"Jeff 'Japhy' Pinyan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Aug 2, awarsd said:
>
> >use lib "/path/to/Module";
> >it works just fine
>
> >with $dir = '/path/to';
> >use lib "$dir/Module";
> >it give me an error I also tried use lib qw() but same problem is there a
> >way to fix the problem??
>
> The problem is that 'use' is a compile-time directive, whereas assigning a
> value to $dir happens at run-time.
>
> When Perl runs your program, it does a preliminary sweep over it, and does
> things like include modules when 'use'd, and execute BEGIN blocks.
>
> A statement like 'use lib "..."' is really just
>
>   BEGIN {
>     require lib;
>     lib->import("...");
>   }
>
> so it happens at compile-time.  This means that your variable $dir, which
> gets assigned at run-time, won't have a value when you need it to.  Here's
> a simple demonstration:
>
>   $x = 2;
>   BEGIN {
>     print "x is '$x'\n";
>   }
>
> That prints "x is ''", because the BEGIN block happens before we set $x to
> 2.  You probably want to require() your config file in a BEGIN block
> before you do 'use lib'.
>
>   BEGIN { require "my_vars.pl" }
>   use lib "$dir/...";
>
> -- 
> Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
> <stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
> [  I'm looking for programming work.  If you like my work, let me know.  ]
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to