Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Is "use vars" safe to use? The current Perl documentation says that's obsolete, and "our" is supposed to be used instead.

My interpretion of "our" is that it's roughly analogous to "extern" in C/C++. I.e., it doesn't allocate space for a variable, but rather brings a variable defined elsewhere into the current scope. But I'm not sure if that's really accurate.

To refresh my memory, I dug out an old Perl script I wrote a couple of years ago to see how I handled this situation. Here's an extract that illustrates the method. Some of this I had to figure out by trial and error, and may not be the best way of doing it.

fsConfig.pm - configuration module - defines class fsConfig

Code
package fsConfig;

use strict;
use re 'taint';

# constants
use constant MAX_ID => 999_999; # warning - don't change this
use constant FTP_TIMEOUT => 15; # seconds
use constant MAX_SEARCH_RESULTS => 100; # max number of items returned by search

# class constructor
sub load {
my $invocant = shift;

my $self = {
...
'submissions_mode' => 'restricted',
...
};

my $class = ref($invocant) || $invocant;
return bless($self, $class);
}

# accessor methods

...

sub submissions_mode {
my $self = shift;
return $self->{'submissions_mode'};
}

...

1;
main.cgi - example module that accesses configuration parameters

Code
#!/usr/bin/perl -wT

use strict;
use re 'taint'; # suppress untainting by regexes

use fsConfig();

# instantiate configuration object and store it in a global variable
$::Config = fsConfig::->load() or die 'Failed to load configuration data';

# suppress warning 'name used only once' (?)
our $Config;

...

# example of accessing configuration constant:
print "The FTP-timeout parameter is " . $Config->FTP_TIMEOUT . "n";

# example of accessing configuration variable:
print "The submissions-mode is " . $Config->submissions_mode() . "n";

...
Critique is welcome smile

Sponsored Links
Entire Thread
Subject Posted By Posted
Loading a package from another package Dave_L 10/08/2003 5:21 AM
Re: Loading a package from another package Charles Capps 10/08/2003 5:39 AM
Re: Loading a package from another package Dave_L 10/08/2003 6:11 AM
Re: Loading a package from another package Charles Capps 10/08/2003 6:28 AM
Re: Loading a package from another package Burak 10/08/2003 6:04 PM
Re: Loading a package from another package Dave_L 10/08/2003 6:43 PM
Re: Loading a package from another package Burak 10/08/2003 6:55 PM
Re: Loading a package from another package Charles Capps 10/08/2003 7:24 PM
Re: Loading a package from another package Burak 10/08/2003 7:40 PM
Re: Loading a package from another package Dave_L 10/08/2003 7:56 PM
Re: Loading a package from another package Charles Capps 10/08/2003 8:27 PM
Re: Loading a package from another package Burak 10/08/2003 8:35 PM
Re: Loading a package from another package Dave_L 10/08/2003 8:41 PM
Re: Loading a package from another package Dave_L 10/08/2003 8:52 PM
Re: Loading a package from another package Burak 10/08/2003 8:58 PM
Re: Loading a package from another package Dave_L 10/08/2003 9:09 PM
Re: Loading a package from another package Burak 10/08/2003 9:39 PM
Re: Loading a package from another package Dave_L 10/08/2003 11:31 PM
Re: Loading a package from another package Burak 10/08/2003 11:37 PM
Re: Loading a package from another package Burak 10/08/2003 11:38 PM
Re: Loading a package from another package Dave_L 10/09/2003 7:58 AM
Re: Loading a package from another package Charles Capps 10/09/2003 8:04 AM
Re: Loading a package from another package Dave_L 10/09/2003 8:17 AM

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Bill B
Bill B
Issaquah, WA
Posts: 87
Joined: December 2001
Forum Statistics
Forums63
Topics37,575
Posts293,931
Members13,824
Most Online6,139
Sep 21st, 2024
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Gizmo 1
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2025 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.1
(Snapshot build 20240918)