Textual inclusion of files into a script.

D

ddtl

Hello,

Is it possible to textually include external files into a perl script,
the way C/C++'s 'include FILE' does? I don't want to use
do/eval/use/require for that purpose, because using those imposes
additional requirements. For example, in order to use 'eval', additional
code to open and read the files is required, and private ('my') variables
from the 'eval'ed files are not accessible.

I just want to be able to split the original file into smaller
pieces and have them assembled back automatically by the compiler,
so that the semantics would be identical in both cases.

ddtl.
 
B

Brian McCauley

ddtl said:
Is it possible to textually include external files into a perl script,
the way C/C++'s 'include FILE' does?

Yes if you run Perl with -P then it will support C-style #includes.
At least it will where a C preprocessor is installed where perl
expects it to be.

However, I wouldn't really recommend it.
I don't want to use
do/eval/use/require for that purpose, because using those imposes
additional requirements. For example, in order to use 'eval', additional
code to open and read the files is required,

Er, yes but you don't need this code if you use 'do' so that's not
really an issue is it?
and private ('my') variables
from the 'eval'ed files are not accessible.

Use the right tool for the job. You want a program in a style that
uses lots of global variables. This is generally considerd a bad
programming style. But if you are completely determined to use it
just declare your global variables using "use vars" rather than my.
I just want to be able to split the original file into smaller
pieces and have them assembled back automatically by the compiler,
so that the semantics would be identical in both cases.

I would say your best course of action is to stop wanting that, it is
a bad thing to want.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
B

Bill

ddtl said:
Hello,

Is it possible to textually include external files into a perl script,
the way C/C++'s 'include FILE' does? I don't want to use
do/eval/use/require for that purpose, because using those imposes
additional requirements. For example, in order to use 'eval', additional

But eval or its equivalent is basic to the perl include system (use
and require). Really, when you run a program in perl, you are doing
this:

eval { my program's text here };

since perl is an interpreted language.

There is also the whole namespace problem--perl may keep variables
defined as lexicals with
my i;
in separate files in separate namespaces unless it is told otherwise.

If the issue is just one of extra programming though, look at

Module::Load

on CPAN. May help simplify loading for you.


-hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top