in reply to Re^2: Installing Sybase::DBlib problems
in thread Hello Word\n

yeah i tried the logical route but failed miserably. I still get the same error message...

if($param eq "send"){ sendMounts() } elsif($param eq "recv") { use lib './lib'; use Sybase::DBlib; }
So the senders don't even need the Sybase::DBlib but the script still dies on use Sybase::DBlib

Replies are listed 'Best First'.
Re^4: Installing Sybase::DBlib problems
by shmem (Chancellor) on Nov 20, 2008 at 13:28 UTC

    use is compile time. It gets executed regardless of the elsif clause. You could use require:

    elsif($param eq "recv") { use lib './lib'; require Sybase::DBlib; Sybase::DBlib->import; # if any imports }
Re^4: Installing Sybase::DBlib problems
by almut (Canon) on Nov 20, 2008 at 13:29 UTC

    That's not the way to do it.  use statements are being executed at compile time, and the condition is being evaluated at runtime.

    That's what the if module is for... (or use require instead of use)

      Thanks almut and all Monks who offered their wisdom!

      I didn't know about the 'if' module

      use lib './lib'; use if $ARGV[0] eq "recv", Sybase::DBlib;
      Regards
      John

        Just two more things to be aware of.  It's usually better to specify the module name as a string ("Sybase::DBlib")1, otherwise you'd get a "Bareword ... not allowed" error when running under "use strict".

        Second, the "use if ..." condition is tested at compile time. In this particular case with $ARGV[0] this is not a problem, because the variable is initialized early on. But if you use some other variable, you might need to wrap its assigment in a BEGIN {...} block...

        ___

        1 only with "use if", that is — with plain "use", in contrast, a bareword is needed.