Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
IMO, the DB hack is a cleaner solution, because it is faster, uses a documented feature ...

I don't think any of them would be much faster than the other. The source filter is documented too.

and has clean syntax for using it. To achieve such clean syntax with a source filter, you need to write a complex regex.

It's not that simple. The difference is that the code I gave above does the include in compile time, and its syntax is use Filter::Include "file" (the do is not needed when including complete statements). The DB way includes the code at run-time, that's why it's possible to use a simple subroutine include "file" is possible. While it is indeed not possible to make my solution work with such a simple syntax, without actually interpreting the code (incidentally that's what the actual Filter::Include cpan module does); if you wanted to modify the DB solution so that it includes the code in compile time (which can be a difference in semantics, depending on what the include file contains), you'll have to use a use or BEGIN syntax too, or try to parse the code.

Besides that, source filters don't work everywhere (like in eval)...
That's true. More generally, source filters can be used only at compile-time, not runtime. Also, source filters can not be used from command line (-e) it seems.
and I really think the included file should by itself be syntactically correct. Including code is bad, but including partitial expressions is, IMHO, even worse.

True. I just wanted to show that this is really including the file.

Finally let me note that some include facility is already built in perl: the -P switch. If the file third contains

#!perl -w use warnings; use strict; my(@a, @b); @a = ( 1, 2, #include "./second" 7, 8); print "a(@a) b(@b)\n"; __END__
and you run it with perl -P third, you get the same results. Of course, perlrun warns you that there are lots of problems with the -P switch.

In reply to Re^3: Including files by ambrus
in thread Including files by Juerd

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 perusing the Monastery: (5)
As of 2024-03-28 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found