Re: use string in "use"

Jim Gibson <[email protected]>
Newsgroups gmane.comp.lang.perl.beginners
Message-ID <[email protected]>
I have not used it myself, but the ‘if’ module allows one to load modules conditionally:

use if CONDITION, MODULE => ARGUMENTS;

See ‘perldoc if’ for more details.


> On Dec 14, 2020, at 7:23 AM, Gary Stainburn <[email protected]> wrote:
> 
> I've written my first re-usable modules in Perl, and all goes well. However, I want to know if / how I can use a string variable in the 'use' clause.
> 
> In PHP I have a simple system of turning on/off debugging and version control.  Any file *1.html is development version.  I then have
> 
> $DEBUG=(preg_match('/1.htm/',$_SERVER['REQUEST_URI'])) ? '1' : '';
> include_once("sql$DEBUG.inc");
> include_once("security$DEBUG.inc");
> 
> This way I have a live and a development version of every HTML and every inc file, and putting any one file is simply a case of copying that file over.
> 
> I'm looking to replicate  this in Perl.  How can I do the following?
> 
> #!/usr/bin/perl -w
> 
> use warnings;
> use strict;
> 
> my $DEBUG=($0=~/1$/) ? '1' : '';
> use RW::Sql$DEBUG;
> use RW::Docs$DEBUG;
> 
> I've found that you can use "require" and pass a path.  I understand that require is run time, while use is compile time.  Are there any down-sides to using require?
> 
> -- 
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
> 
> 

Jim Gibson

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.