SPUG: use strict and do files.

Stuart Poulin stuart_poulin at yahoo.com
Fri Jul 30 12:23:26 CDT 1999



--- Doug Beaver <dougb at scalar.org> wrote:
> On Thu, Jul 29, 1999 at 07:34:33PM -0700, charles.e.derykus at boeing.com wrote:
> > > Stu Poulin wrote:
> > > I was looking for a cheap rc type file behavior.  I thought I could
> > > just use a "do" file with variables in it - but I wanted "use
> > > strict" to be enforced. The perlfunc man page says:
> > >    do 'stat.pl';
> > >      is just like
> > >    scalar eval `cat stat.pl`;
> > 
> > > This doesn't appear to be true.  This is on win98 so s/cat/type/ but
> > > "type" is expensive as far as run time.  Is there a way to force a
> > > "use strict" on do files?
> > 
...
>  
> The funny thing is, if you add C<use strict> to doit.pl, then you have
> to declare the variables as either globals (with C<use vars> or by
> stating the package name explicitly) or make them lexical.
> 
Yes, a use vars is in the original message.
>
... 
> You can still use do() to implement a quick and useful rc system though:
> 
> -------
> doit.pl
> -------
> $LOGGING_DAEMON_CONFIG = {
>     logdir => '/var/log',
>     proclimit => 32,
>     valid_domains => [qw/ibm.com sun.com hp.com/],
> };
> --snip--
> 

My idea of cheap was to declare some variables with "use vars" and let perl
toss an error if a name was mispelled or a unknown variable was set.
Using a hash I'd have to parse for unknown keys myself.  (Of course that'd be
easier than writing all this email ;-)

But you did give me an idea.  I though "What if I use the new psuedo hash? 
That'd be easy!"
Alas, it doesn't work with "do" because it's a compile time verses runtime
issue.  But it does work with "require".   So maybe that's what I'll use.
Thanks,
  Stu

#!perl -w

use strict;

package doit;
use vars qw($parms);
$parms = [ { one=>1, two=>2 }, "main_one", "main_two" ];
print "$doit::parms->{one}  $doit::parms->{two}\n";

# $parms->{whoops} = "whoops"; # Does toss an error with do :-) Compile time.

# do "doit.pl";
require "doit.pl";

package main;
print "$doit::parms->{one}  $doit::parms->{two}\n";

__END__



# doit.pl
#use strict;

$parms->{one} = "doit_one";
$parms->{two} = "doit_two";
$parms->{whoops} = "error";  # doesn't toss an error with "do" -  Runtime


_____________________________________________________________
Do You Yahoo!?
Free instant messaging and more at http://messenger.yahoo.com


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list