Home: Perl Programming Help: Beginner:
Can I put the USE statement separately?



ljroger
Deleted

Apr 27, 2001, 7:50 AM


Views: 314
Can I put the USE statement separately?

Can I put the USE statement separately? For example:

#!/usr/bin/perl

use strict;
my $current_dir = `pwd`;
if ( $current_dir cmp "......") {
use lib ("......"); }
else {
use lib ("....."); }

use ....;
.....





japhy
Enthusiast

Apr 27, 2001, 10:58 AM


Views: 310
Re: Can I put the USE statement separately?

Doing use happens at compile time, so your if-statements are useless. Try something like:


Code
BEGIN { 
require lib;

chomp( my $pwd = `pwd` );
# or use the Cwd module
# use Cwd;
# my $pwd = cwd();

if ($pwd ne '/some/specific/dir') {
lib->import($pwd);
}
else {
lib->import('/other/dir');
}
}

The BEGIN { ... } ensures that the code happens at compile time, like a use lib ... would.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


ljroger
Deleted

Apr 30, 2001, 7:01 AM


Views: 301
Re: Can I put the USE statement separately?

Thanks, Japhy. Problem is solved.

Roger