using the require command with perl
Hi,
I'm trying to use the require command with perl but when i want to put a variable within the require statement it always errors out. The code looks something like this.
require "/absolute/path/to/files/$FORM{'id'}/options.txt";
Is this not possible? thanx for the help.
Mark Hensler posted this at 07:14 — 26th October 2001.
He has: 4,048 posts
Joined: Aug 2000
Have you tried echoing the string to check the path?
I don't think I've ever tried that with Perl, but it works in PHP.
tmay posted this at 21:21 — 28th October 2001.
They have: 75 posts
Joined: Sep 2001
Try to do this:
eval("require \"/absolute/path/to/files/$FORM{'id'}/options.txt\";");
But don't forget to check ID! Eval is very insecure, if you use it bad...
For example, if $FORM{'id'} is a number, this code is much more secure:
$id=$FORM{'id'}+0;
eval("require \"/absolute/path/to/files/$id/options.txt\";");
If I'm totally wrong here, explain exactly what you are trying to do and what options.txt is and why you are calling it.
-Troy May
PC Sympathy
Admin at HFT Online
tmay posted this at 22:17 — 28th October 2001.
They have: 75 posts
Joined: Sep 2001
Also, you do know that whatever you require has to have some prewritten Perl code in it, right? The require command actually imports a program, not a regular text file.
-Troy May
PC Sympathy
Admin at HFT Online
Mark Hensler posted this at 06:18 — 29th October 2001.
He has: 4,048 posts
Joined: Aug 2000
In order to require a page that has a path constructed with a variable, do you need to eval it? Or should it work without the eval?
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.