SPUG: use strict and do files.
charles.e.derykus at boeing.com
charles.e.derykus at boeing.com
Thu Jul 29 21:34:33 CDT 1999
> 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?
Stu,
I noticed now that Tom Christiansen has amended the docs
slightly to say:
do $file is like eval `cat $file`, except the former:
1.1 searchs @INC and updates @INC
1.2 bequeaths an unrelated "lexical" scope on the eval'ed code
(See: http://x32.deja.com/[ST_rn=ps]/getdoc.xp?AN=503977526&CONTEXT=933300222.1535180873&hitnum=1)
That's rather confusing though and doesn't account for instance
why 'use constant' is visible whereas 'use strict' pragma isn't
in the case below:
package main;
...
package doit:
use strict; # doesn't propagate to 'do file'
use constant CONS => 3 # does " " "
package main;
package doit;
do "doit.pl";
#--------------------------
# doit.pl
$whoops = "toss_an_error";
print "CONS = ", CONS, "\n"; # prints CONS = 3
So, you'll probably have to insert a 'use strict' in doit.pl
unless I'm missing something.
Regards,
--
Charles DeRykus
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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