Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: using strict and a config file

by snowcrash (Friar)
on Nov 12, 2001 at 13:13 UTC ( [id://124777]=note: print w/replies, xml ) Need Help??


in reply to using strict and a config file

You probably require the configfile. That happens during runtime, so the interpreter doesn't know about @fields when compiling the script. Either put the configuration into a perl module you import via use or tell the interpreter you have a variable named @fields.
**** script.pl **** #!/usr/bin/perl use warnings; use strict; use vars qw(@fields); require "conf.pl"; print $fields[0]; **** conf.pl **** @fields = qw( FOO BAR BAZ );
hth, snowcrash

Replies are listed 'Best First'.
Re (tilly) 2: using strict and a config file
by tilly (Archbishop) on Nov 12, 2001 at 14:09 UTC
    While using modules is a Good Thing™ in general, in this case it is a red herring. Whether you make your configuration into a module or not doesn't affect what you need to do to allow globals to be accessed while strict is on.
Re: Re: using strict and a config file
by lex2001 (Sexton) on Nov 12, 2001 at 13:56 UTC
    I got my config file to work -- Thanks! I have a question concerning modules. If I where to create a module config file would it be possible to save it (and make it work) in the same directory that contains the main perl script or in my user directory -- such as: home/users/username From what I have read is seems like the best places are in paths like /usr/lib/perl5/ or /usr/local/apache/perl-lib/ but I may not be able to place them in these locations thanks...
      Yes it is possible. All you have to do is
      use lib '.';

      at the beginning of your program.

      This will make Perl look for modules in the current directory too.

Re: Re: using strict and a config file
by Amoe (Friar) on Nov 12, 2001 at 21:39 UTC
    Just FYI...

    I believe use vars is now obsolete, as it has been superseded by our.

    --
    my one true love

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124777]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-25 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found