From: SSC_perl p...@surfshopcart.com
Octavian,
Thanks for the reply.
So I tried the following:
use lib ss_files;
This also works, but iirc, I read that it won't work across all platforms.
Is that correct?
This method also works, but to be equivalent with the first method it should
have been:
use lib ../ss_files;
Actually, that doesn't work. Adding ../ breaks the script.
This means that the modules are not in the ../ss_files directory.
In the example that use FindBin you used a path like $Bin/../ss_files. That
path should have been $Bin/ss_files to be equivalent with just ss_files.
If you change the current directory to be another directory, like /home/user
for example, it won't work, because it will search for modules in
/home/ss_files.
The directory won't change once the script is installed. Both shop.cgi and the
ss_files directory are in the surfshop directory and will always remain there.
The surfshop directory could, in theory, be placed anywhere, but that shouldn't
have any effect on shop.cgi calling the other files, no?
I think you don't understand what Current directory means. :-)
I've seen that the script has a .cgi extension, so it might be a CGI script
which is ran by a web server only, but even CGI scripts may be ran manually, so
here I try to explain again:
Let's say you have the path:
/home/user/surfshop
If you always do:
$ cd /home/user/surfshop
$ ./shop.cgi
Then the current directory is /home/user/surfshop, which is also the parent
directory of the shop.cgi script.
And you can use without any problem:
use lib ss_files;
Because it will search for the directory ss_files in the current directory.
But if you will change the current directory to another one, and then run the
script, using:
$ cd /
$ ./home/user/surfshop/shop.cgi
Then the script it won't work if you use just:
use lib ss_files;
Because the current directory is just / and it will search for the directory
with modules /ss_files.
If you use FindBin, then the variable $Bin will get the path to the directory
in which is placed the shop.cgi script, which is /home/user/surfshop, so if you
use:
use lib $Bin/ss_files
it will always search for the directory with modules at
/home/user/surfshop/ss_files, no matter what's the current directory where you
started the script.
If the script is a CGI script, the web server might get the path to this script
and set the current directory to that path, so use lib ss_files may work, but
I don't know if it is always the case... if all web servers that can run Perl
CGI scripts do the same. So it is more secure to use FindBin.
Octavian
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/