Re: Locating files in sub-directories

2013-12-17 Thread SSC_perl
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.

 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?

If that's the case, I like  use lib ss_files;  simply because it's 
short and sweet.  If no one knows of a problem with portability, then I'll 
stick with it.  I just don't want someone to download our cart and then have a 
problem with it simply because I wasn't able to test it properly.

Thanks again,
Frank

SurfShop v1.5.2 Released
http://www.surfshopcart.com/forrumm/viewtopic.php?f=2t=298

-

For the sake of completeness, I ran across another way to locate files 
in a sub-directory here:

http://learn.perl.org/faq/perlfaq8.html#How-do-I-add-the-directory-my-program-lives-in-to-the-module-library-search-path-

BEGIN {
use Cwd;
our $cur_directory = cwd;
}
use lib $cur_directory/ss_files;
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Locating files in sub-directories

2013-12-17 Thread Octavian Rasnita
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/




Locating files in sub-directories

2013-12-16 Thread SSC_perl
I'm in the process of moving certain files of the SurfShop script into 
a sub-directory to clean up the main directory and would like to know the best 
way for the script to find these files.

I was using this method:

use FindBin qw($Bin);
use lib $Bin/../ss_files;

which worked for me, but I read somewhere that FindBin can break in certain 
situations.  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?

Is one of these methods better than the other, or is there another way 
that I haven't found yet?

Thanks,
Frank

SurfShop v1.5.2 Released

http://www.surfshopcart.com/forrumm/viewtopic.php?f=2t=298
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Locating files in sub-directories

2013-12-16 Thread Octavian Rasnita
From: SSC_perl p...@surfshopcart.com

I'm in the process of moving certain files of the SurfShop script into a 
sub-directory to clean up the main directory and would like to know the best 
way for the script to find these files.

I was using this method:

use FindBin qw($Bin);
use lib $Bin/../ss_files;

which worked for me, but I read somewhere that FindBin can break in certain 
situations.

I have never met a situation in which FindBin was not working. But I haven't 
met all possible situations in the world, so... :-)
So this method is very good.


 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;

This second method has a big limitation though. If The current directory when 
you run the script is the directory in which is place the script, then it will 
work.
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.

Using FindBin will always get the path to the directory in which is placed the 
script you run, and then the line use lib will set the path of modules 
starting from that path and not from the current directory.


Is one of these methods better than the other, or is there another way that I 
haven't found yet?


The first method is better because it will work even if you change the current 
directory. And you can run the scripts from a cron job for example.
Octavian


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/