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: Intermediate:
using variables from a file full of variables, Exporter

 



Iconx
Novice

Dec 5, 2014, 4:06 PM

Post #1 of 2 (2864 views)
using variables from a file full of variables, Exporter Can't Post

I've been working on this script that got dropped on my desk that was written without strict and I've been trying to make it strict. My question is whether its possible with strict to have a module that holds a bunch of variables be pulled into a script with value. Here's what I've got so far, this is a bit simplified and the vars come in blank, obviously declared but no value. How do you do this?

Details:

Variables.pm

Code
package Variables; 
use parent 'Exporter';
our @EXPORT = qw($YPMATCH $GROUPADD $EMAIL);

my $YPMATCH = '/usr/bin/ypmatch';
my $GROUPADD = '/usr/bin/groupadd';
my $EMAIL = 'admin@whatever.com';


script.pl

Code
#!/usr/bin/perl 

use strict;
use Variables;

print "EMAIL is $EMAIL \n";
print "YPMATCH is $YPMATCH \n";


Been struggling with this for a while.


FishMonger
Veteran / Moderator

Dec 5, 2014, 6:41 PM

Post #2 of 2 (2857 views)
Re: [Iconx] using variables from a file full of variables, Exporter [In reply to] Can't Post

If you declare the vars as globals instead of lexicals (i.e., use our instead of my keyword) your script will work. However, you almost never want to export the vars. Instead, you should create accessor/mutator functions that return the value of the vars.

 
 


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

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