include processed by a C preprocessor : no syntax analysis is done
Aha, I see where you're coming from now. Unfortunately perl really isn't geared towards source manipulation in that way - all its including functions must evaluate the code in the given file before including it into the parent source, such is the nature of perl. This behaviour is due to the fact that perl is a semi-interpreted dynamic language (it's compiled down to internal bytecode and then executed within perl) so when you require a file it is performed at runtime and therefore must be syntactically sound and pass any strictures that might be in place. As for use that's just a require done at compile-time and also calls the import method of the given package.

So, finally, to answer your question (as I now understand it ;), no, perl has no 'simple 'include'.
But here's one I made earlier (as it were)

package include; use IO::File; use Regexp::Common 'quoted'; use Filter::Simple; =head1 SYNPOSIS use include; include Foo::Bar; include "somefile.pl"; =cut FILTER_ONLY code => sub { local $/; s< ^ \s* include \s+ (.*?) ; $> ( my $f = $1; if($f =~ /^['"]) { (undef, undef, $f) = $f =~ $RE{quoted}{-keep}; } else { ($f = "$f.pm") =~ s<::>(/)g; } my $fh = IO::File->new($f) or die("include: $!"); $fh->getlines )xg; } ;
Roughly, the code should act like #include does in C by just dropping the source of the given package or file in place. It's untested at the moment, but hopefully it should DTR. There's also Text::MacroScript but I'm not sure if that meets your needs of a 'simple include' (although my gruesome filter is hardly simple ;).
HTH

_________
broquaint


In reply to Re: Re: Re: Re: Re: Re: Re: a simple include.... by broquaint
in thread a simple include.... by pcouderc

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



  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.