Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found