CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



ljroger
Deleted

Apr 27, 2001, 7:50 AM

Post #1 of 3 (328 views)
Can I put the USE statement separately? Can't Post

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

Post #2 of 3 (324 views)
Re: Can I put the USE statement separately? [In reply to] Can't Post

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

Post #3 of 3 (315 views)
Re: Can I put the USE statement separately? [In reply to] Can't Post

Thanks, Japhy. Problem is solved.

Roger


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives