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.
really think the included file should by itself be syntactically correct.
Including code is bad, but including partitial expressions is, IMHO, even
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
use warnings; use strict;
@a = (
print "a(@a) b(@b)\n";
and you run it with perl -P third
, you get the
Of course, perlrun
warns you that there are lots of problems
with the -P switch.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||