Using strict with do and a config file 
Author Message
 Using strict with do and a config file

I would like to 'use strict'  in a collection of scripts that all import
some variables from a single config file, and I cannot figure out how to do
it.

I've been using a do statement to "import" some constants from a config file
into several scripts.  Unfortunately, this apparently means I cannot 'use
strict' in the scripts.  (I suppose this is because the constants are scoped
to the do statement.  Is that right?)  I am so accustomed to using strict,
that flying without it is turning me into a nervous wreck.

I thought the alternative would be to declare the variables in the config
script as global, but that doesn't work.  (More specifically, I still get
the "Global symbol "$blah" requires explicit package name . . ." error.

Here's the way I am importing from the config file:

  my $configfile = 'configuration_file';
  unless (my $return = do $configfile) {

    warn "couldn't do $configfile: $!"    unless defined $return;
    warn "couldn't run $configfile"       unless $return;
  }



Mon, 30 Aug 2004 22:08:27 GMT  
 Using strict with do and a config file
When you use 'use strict' directive, and after that import/require file with some varibles then you must use 'use vars qw[$first $secnd $another];

Example:

e.conf
#!/usr/bin/perl

$first = 1;
$second = 2;
$another = 'varaible';

1;

e.pl
#!/usr/bin/per -w
use strict;

require 'e.conf';
use vars qw [$first $secnd $another];

...

Marek

On Thu, 14 Mar 2002 14:08:27 GMT

Quote:

> I would like to 'use strict'  in a collection of scripts that all import
> some variables from a single config file, and I cannot figure out how to do
> it.

> I've been using a do statement to "import" some constants from a config file
> into several scripts.  Unfortunately, this apparently means I cannot 'use
> strict' in the scripts.  (I suppose this is because the constants are scoped
> to the do statement.  Is that right?)  I am so accustomed to using strict,
> that flying without it is turning me into a nervous wreck.

> I thought the alternative would be to declare the variables in the config
> script as global, but that doesn't work.  (More specifically, I still get
> the "Global symbol "$blah" requires explicit package name . . ." error.

> Here's the way I am importing from the config file:

>   my $configfile = 'configuration_file';
>   unless (my $return = do $configfile) {

>     warn "couldn't do $configfile: $!"    unless defined $return;
>     warn "couldn't run $configfile"       unless $return;
>   }



Mon, 30 Aug 2004 22:46:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. 'Do', config files and strict

2. Using .pm file and @EXPORT for global config file

3. use strict and use Config ??

4. Using Web Frontend to make Config file

5. Using File::Find with 'use strict'

6. Reading configuration files using strict

7. PERLFUNC: endservent - be done using services file

8. PERLFUNC: endpwent - be done using passwd file

9. PERLFUNC: endprotoent - be done using protocols file

10. PERLFUNC: endnetent - be done using networks file

11. PERLFUNC: endhostent - be done using hosts file

12. PERLFUNC: endgrent - be done using group file

 

 
Powered by phpBB® Forum Software