Textual inclusion of files into a script.

Discussion in 'Perl Misc' started by ddtl, Jun 25, 2004.

  1. ddtl

    ddtl Guest

    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.
    ddtl, Jun 25, 2004
    #1
    1. Advertising

  2. ddtl <this.is@invalid> writes:

    > 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\\
    Brian McCauley, Jun 25, 2004
    #2
    1. Advertising

  3. ddtl

    Bill Guest

    ddtl <this.is@invalid> wrote in message news:<>...
    > 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
    Bill, Jun 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John E

    Textual Equivalent

    John E, Dec 22, 2003, in forum: Java
    Replies:
    5
    Views:
    408
    Roedy Green
    Dec 22, 2003
  2. Sean Aitken
    Replies:
    1
    Views:
    270
  3. Replies:
    2
    Views:
    349
  4. Larion
    Replies:
    1
    Views:
    1,819
    jcsnippets.atspace.com
    Mar 26, 2006
  5. Franz Hose

    Textual data files in C

    Franz Hose, Feb 5, 2008, in forum: C Programming
    Replies:
    7
    Views:
    320
    Barry Schwarz
    Feb 8, 2008
Loading...

Share This Page