<?xml version="1.0" encoding="windows-1252"?>
<node id="393480" title="Re^3: Including files" created="2004-09-24 08:38:41" updated="2005-08-11 20:37:13">
<type id="11">
note</type>
<author id="295576">
ambrus</author>
<data>
<field name="doctext">
&lt;blockquote&gt;
IMO, the DB hack is a cleaner solution, because it is faster, uses a
documented feature ...
&lt;/blockquote&gt;
&lt;P&gt;
I don't think any of them would be much faster than the other.
The source filter is documented too. 
&lt;blockquote&gt;
and has clean syntax for using it. To achieve such clean syntax with a source filter, you need to write a complex regex.
&lt;/blockquote&gt;
&lt;P&gt;
It's not that simple.  
The difference is that the code I gave above does the include
in compile time, and its syntax is &lt;code&gt;use Filter::Include "file"&lt;/code&gt;
(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 &lt;code&gt;include "file"&lt;/code&gt;
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
[cpan://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 &lt;code&gt;use&lt;/code&gt; or &lt;code&gt;BEGIN&lt;/code&gt; 
syntax too, or try to parse the code.

&lt;blockquote&gt;
Besides that, source filters don't work everywhere (like in eval)...
&lt;/blockquote&gt;
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.

&lt;blockquote&gt;
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.
&lt;/blockquote&gt;
&lt;P&gt;
True. I just wanted to show that this is really including the file.
&lt;P&gt;
Finally let me note that some include facility is already
built in perl: the -P switch. If the file &lt;b&gt;third&lt;/b&gt;
contains 
&lt;code&gt;
#!perl -w
use warnings; use strict;
my(@a, @b);
@a = (
1, 2,
#include "./second"
7, 8);
print "a(@a) b(@b)\n";
__END__
&lt;/code&gt;
and you run it with &lt;code&gt;perl -P third&lt;/code&gt;, you get the
same results.
Of course, [perlrun] warns you that there are lots of problems
with the -P switch.


</field>
<field name="root_node">
393426</field>
<field name="parent_node">
393465</field>
</data>
</node>
