Gossamer Forum
Home : General : Perl Programming :

uses strict and require

Quote Reply
uses strict and require
My apologies if this is redundant. I didn't get the exact anwser that I was looking for from the older posts. This is what I want:

use strict;
our $HOMEPATH = "$ENV{'DOCUMENT_ROOT'}";
require 'conf.pl';
make some use of $CGIBINDIR;

inside of conf.pl:

$CGIBINDIR = $HOMEPATH . "/cgi-bin";

This works fine without use strict; using strict gives me this error: Global symbol "$CGIBINDIR" requires explicit package name.

If this can't be done, I'd be more than willing to listen to some alternatives to accomplish the same thing regardless of the complexity. I'm just starting the website and want to get use strict working now before it's completely unstrictable.

Thanks,
Marty
Quote Reply
Re: [mfisher_jr] uses strict and require In reply to
You need to declare that variable.....

my ($CGIBINDIR);
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] uses strict and require In reply to
So, I put a my $CGIBINDIR; before the require and the value was returned filled after the require. Thanks.

However, I had wanted to use the conf.pl like a .h file in C. Declaring all of the variables before the require defeats the purpose of declaring them in one spot.

Do you have another suggestion?

Thanks again,
Marty
Quote Reply
Re: [mfisher_jr] uses strict and require In reply to
After discovering the Modules chapter in 'Programming Perl', I changed config.pl to Config.pm and added the following to the new module:

package Config;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw($CGIBINDIR);

I still can't access $CGIBINDIR from outside of the module. The book says that I should be able to access it after a use or require on Config.pm. When the book says something and I can't do it; it's usually me.

Any suggestions?
Marty
Quote Reply
Re: [mfisher_jr] uses strict and require In reply to
Is it really necessary to declare $CGIBINDIR in the conf.pl?

If not, the simple way could be...

The full path to your cgi-bin directory would be:
our $CGIBINDIR = "$ENV{'DOCUMENT_ROOT'}/cgi-bin";

You may want to look at Tools::Load,

http://search.cpan.org/...04/lib/Tools/Load.pm

Thanks,

Zeshan.