Does Perl have an include statement, or something similar to C's "#include"?
The statement you're looking for is require. At a command prompt, typing
perldoc -f require
will get you more info. Also check out the use statement, which refines require in interesting and useful ways.
| [reply] [d/l] [select] |
Apart from use and require it as also possible to do a file. On the file include spectrum, do would be the rawest method, and use would be the most refined.
It should be noted in passing that #include as a concept doesn't really pan out in Perl. Yes, you can embed perl code in external files, but then you must ensure that the code is run a perfectly trusted environment, otherwise Really Bad Shi^WThings can happen. That is, even if a user cannot modify your code, if they can edit a config file that is Perl code waiting to be eval'ed, then you are wide open in terms of security vulnerabilities.
A better approach is to use configuration files to store data, and parse it all. There are a number of modules that make this simple to do. For instance, if you are familiar with Win32-style .ini files, there is a module to do that, and a few more besides.
In any event, you should also read perlsec and tainting, to be make sure that people don't try and make your program do naughty things, like rm -rf /.
--g r i n d e r
just another bofh
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u';
| [reply] |
I should think a source filter would allow a literal include
(along with lots of other mischief). But as my fellow monks
have pointed out, just because you can do an inclusion
doesn't mean you should.
-- Chip Salzenberg, Free-Floating Agent of Chaos | [reply] |
Howdy!
perldoc perlrun shows
-P
causes your script to be run through the C preprocessor before compilation by Perl. (Because both comments and cpp directives begin with the # character, you should avoid starting comments with any words recognized by the C preprocessor such as ``if'', ``else'', or ``define''.)
This will let you use '#include'...but do be mindful of the
security issues others have already raised...
yours,
Michael | [reply] |
My copy is at work, but isn't there also an example of using an eval statement in Perl CookBook if you're actually including code? (Maybe Programming Perl or one of the other O'Reilly Perl books-I'm too tired to remember as I type this.) Anyone?
| [reply] [d/l] |