in reply to including another perl file

The only way to literally include a file is to eval its contents:

eval do { local $/ open my $fh, '<', 'B.pl' or die $!; readline $fh; } +;
Use require and use only with modules (those .pm thingies that have their own packages), because require only loads once and this WILL bite in any persistent environment.

do FILENAME is great, but many people expect lexicals to be shared, so I only recommend eval STRING for file inclusion now. In my mind, there are two ways of programming with multiple files:

  1. Dirty: literal file inclusion. Dirty anyway, so eval STRING is okay;
  2. Clean: generalized modules, used as such. No two files use the same package.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: including another perl file (dynamic scoping)
by Aristotle (Chancellor) on Jun 02, 2003 at 21:27 UTC
    require only loads once and this WILL bite in any persistent environment.
    $ echo 'print 1;' > test.pl $ perl -le'{ local %INC; require "test.pl" } require "test.pl";' 1 1
    Update: that should be local %INC = %INC; in fact.

    Makeshifts last the longest.

      local %INC;

      Good point, but I don't think many people will remember to do that :)

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }