Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Re: Re: Re: Re: a simple include....

by broquaint (Abbot)
on May 03, 2003 at 12:54 UTC ( [id://255311]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Re: Re: a simple include....
in thread a simple include....

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://255311]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found