Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is not an answer to your question, but rather a related observation. Here's the relevant section of the docs for do (my emphasis):

  • do EXPR

    Uses the value of EXPR as a filename and executes the contents of the file as a Perl script. Its primary use is to include subroutines from a Perl subroutine library.
    do 'stat.pl';
    is just like
    eval `cat stat.pl`;
    except that it’s more efficient and concise, keeps track of the current filename for error messages, searches the @INC libraries, and updates %INC if the file is found. … It also differs in that code evaluated with "do FILENAME" cannot see lexi­cals in the enclosing scope; "eval STRING" does.
It may not be not entirely obvious, but the underlined sentence implies that, despite the similarity of the two constructs, with do 'stat.pl' strictures are not enforced, but they are with eval `cat stat.pl`.

In the following example, the file x.pl contains only the line $x = 1;

# y.pl use strict; use warnings; use diagnostics; do 'x.pl'; print 'do: ', +( $@ ? $@ : 'ok' ), "\n"; eval `cat x.pl`; print 'eval: ', +( $@ ? $@ : 'ok' ), "\n"; __END__ do: ok Variable "$x" is not imported at (eval 2) line 1 (#1) (F) While "use strict" in effect, you referred to a global variabl +e that you apparently thought was imported from another module, because something else of the same name (usually a subroutine) is exported + by that module. It usually means you put the wrong funny character o +n the front of your variable. eval: Global symbol "$x" requires explicit package name at (eval 2) li +ne 1.

So you'll need to use eval instead of do if you want strictures, but you'll have to check $@ yourself after the eval.

the lowliest monk


In reply to Re: Can I force strictness on included files? by tlm
in thread Can I force strictness on included files? by Thilosophy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-18 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found