CGI Include

They have: 5,633 posts

Joined: Jan 1970

Just wandering,

In php, to include a file you use the command

include("filename.ect");

What (if anything) would be the perl equivalent to that?

Thanks for the help,

TheSpaceDude
[email protected]
http://www.thespacezone.com

They have: 161 posts

Joined: Dec 1999

You probably want the require() function, or perhaps the do() function. Be warned, files included into your program should end with the line

1;
'

because Perl expects them to return a true value (that indicates success).

They have: 1,587 posts

Joined: Mar 1999

yeah, require will probably do it for u.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

require "file.txt";
require "file2.txt";
require "files.txt";

Most scripts and programmers recommend you have it near the top of the script/program, before the variables, for ease.

Smiling Suzanne

P.S. This was edited to correct my brain fart, thank you!

[Edited by Suzanne on 10-21-2000 at 03:23 AM]

They have: 161 posts

Joined: Dec 1999

No, Suzanne, I'm afraid you can't. require() takes at most one argument, and that argument MUST be the name of a module, or the path to a single file to be included. To include several files at once, make an array of them, and require each element of the array separately:

# pre-5.005 code
for (@files) { require }

# 5.005 and later
require for @files;
'

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

How 'bout this:

require "text1.txt","text2.txt";

like:
print "this","and","this";

They have: 161 posts

Joined: Dec 1999

No, trust me. require does not take a list of files. perldoc -f require

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.