I want to use files that are inside cgi-bin folder in perl, I want to call them from index.cgi When I do this: use cgi-bin/file_name it doesn't work, how can I do that?
A:
You could try "do"
# read in config files: system first, then user
for $file ("/share/prog/defaults.rc", "$ENV{HOME}/.someprogrc")
{
unless ($return = do $file) {
warn "couldn't parse $file: $@" if $@;
warn "couldn't do $file: $!" unless defined $return;
warn "couldn't run $file" unless $return;
}
}
This is from perldoc example.
krico
2010-07-20 09:06:04
thanks it worked.
zeina
2010-07-20 10:04:57
+6
A:
When you ask Perl to use a module, it searches the directories in @INC
. If a module you want to use is located in some other directory, you can do this:
use lib 'some/other/directory';
use TheModule;
If you don't want the directory to be added to @INC
, you can implement use
directly like this:
BEGIN {
require 'some/other/directory/TheModule.pm';
TheModule->import('foo', 'bar', ...);
}
FM
2010-07-20 13:11:42
I assuemd these were no modules, but scripts since they are under cgi-bin/I finde it a little dangerous to add cgi-bin/ to @INC, don't you?
krico
2010-07-21 08:52:38
@krico If they are not modules, why are they `pm` files? Regarding the concern about adding `cgi-bin` to `@INC`, please see the edited answer.
FM
2010-07-21 12:18:07