Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Think about Loose Coupling
 
PerlMonks  

imposing "strict" on an included file

by dpuu (Chaplain)
on Jul 22, 2004 at 21:26 UTC ( #376724=perlquestion: print w/ replies, xml ) Need Help??
dpuu has asked for the wisdom of the Perl Monks concerning the following question:

I have a file that we're including via C<do>. I've has a request to impose strictness and warnings on that file. Warnings are easy ($^W); but stricness is more difficult.

I could obviously slurp the file into a string and prepend a "use strict;" declaration before eval-ing it. I'd have to fix-up the filename in any error messages ("eval 347" is not a very meaningful), but it would be do-able.

The other way I can think of is to do the same prepending, but do it by messing with the filename passed to C<do>:

do qq(cat $filename | perl -ple 'BEGIN { print "use strict;" }');
This doesn't seem ideal, either. Is there a simpler way?

--Dave
Opinions my own; statements of fact may be in error.

Comment on imposing "strict" on an included file
Download Code
Re: imposing "strict" on an included file
by pg (Canon) on Jul 22, 2004 at 21:48 UTC

    Your approach does not always work. Try this piece of code:

    use strict;#suppose this line is added by you no strict; use warnings; $a = "a"; &$a; sub a { print "abc"; }

    This piece of code works with no problem, which disproves your way. You have to check wehther your "use strict" is cancelled in any way.

Re: imposing "strict" on an included file
by gaal (Parson) on Jul 22, 2004 at 22:22 UTC
Re: imposing "strict" on an included file
by BUU (Prior) on Jul 22, 2004 at 23:58 UTC
    Why are you trying to do this? If the library is completely written, working and out of your control, then adding strict and warnings won't cause it to do anything it doesn't already do, except for maybe stop working in new and stupid ways. Otherwise, if the module is still in development, which is the only time strict is useful, why don't you just make whoever is developing it put strict in?
      The files in question define tests for our hardware. In hardware testing, false-passes are the ultimate evil. A false fail can be dealt with (you just get someone to fix it), but a false-pass can make its way into production, un-noticed. Therefore, we'd far rather break modules that are currently seming to work, then to leave them with potentially hidden problems. Adding "use strict" is seen as a bit of low-hanging fruit.

      --Dave
      Opinions my own; statements of fact may be in error.

        So why not just open up the files in question and type "use strict" at the top?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://376724]
Approved by NovMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-04-18 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (461 votes), past polls