develooper Front page | perl.beginners | Postings from December 2020

use string in "use"

Thread Next
From:
Gary Stainburn
Date:
December 14, 2020 15:23
Subject:
use string in "use"
Message ID:
2c2d418f-294f-f904-39c3-5d17361ae07f@ringways.co.uk
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?

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About