0

I apologize if this question is very simple or redundant but I can't figure out how to move a cpan module from local bin to @INC, so it's accessible to other users. I have root rights and used sudo cpan File::Find::Rule to install on Linux server. When I type perldoc -l File::Find::Rule a local path is returned:

/usr/local/share/perl5/File/Find/Rule.pm

How do I get this module in @INC? thank you

Some modules that I'm using are in @INC and others in a local share. The following code gives me an error message that File::Find::Rule is not loaded.

##!/usr/bin/perl
use strict;
use warnings;

use lib '/usr/lib64/perl5/vendor_perl/List/';
use lib '/usr/lib64/perl5/vendor_perl/Data/';
use lib '/usr/local/share/perl5/File/Find/';

my $base_dir = '/data/results';    
my @dirs = File::Find::Rule->maxdepth(1)->directory->in($base_dir);
user3781528
  • 623
  • 6
  • 27
  • Just say `use lib '/usr....';` and this adds the new path to the beginngin of `@INC`. See about this [`in lib`](http://perldoc.perl.org/lib.html#Adding-directories-to-%40INC). There are other ways, of course, for example by setting `PERL5LIB` in your shell. – zdim Jan 19 '17 at 09:52
  • I mean to say this will enable a program to use modules from that location, as well. (It won't move the module anywhere.) Note that this also results in that path being searched for modules first, so if you have different versions there (than where the rest are) then _those_ are going to be used. Where are the modules that you use installed? – zdim Jan 19 '17 at 10:03
  • It's very confusing because some of the modules (such as File::Find) are in /usr/share/perl5/File/Find.pm, however, File::Find::Rule is in /usr/local/share/perl5/File/Find/Rule.pm. Also, I'm worried about other users being able to use the script with modules on the local share. Thanks – user3781528 Jan 19 '17 at 20:42
  • I see. But it's common to have segregated installations, and often useful. User libraries always go elsewhere. That is what `lib` pragma is for -- you can set up `@INC` with it in one line at the top of the script. Or, with `PERL5LIB` in the shell-config file (`.bashrc` for example) a user can set it for all their programs. (Can use both, too.) The `/usr/local/` is a very common system location. Users need to be able to figure out whether modules are installed and where, and to load them. There is no need to have all modules at one place, and is often unreasonable. – zdim Jan 19 '17 at 21:02
  • unfortunately, I'm the only one in the department who knows anything about Perl/programming. You can see that I don't know much. I will have to set up everything for other users. I've tried `use lib '/usr/local/share/perl5/File/Find/Rule.pm';` but get an error message Parameter to use lib must be directory, not file at Error_Check_Two.pl line 6. – user3781528 Jan 19 '17 at 21:10
  • Correct, `lib` takes directories. So just `use lib '/usr/local/share/perl5';` and it's going to find all packages that it needs _in that directory_. As for other users, if they merely use (run) your scripts then it's all fine. You include needed directories and the scripts will run. If _they_ write programs ... I'm afraid they'll have to learn how to load libraries. You can't solve that for them. You could put out a web page or such, with instructions. If you need to do that, there are excellent SO posts on how to set up `@INC` (so that modules can be found). – zdim Jan 19 '17 at 21:34
  • Also, first check what is already there -- `print "$_\n" for @INC;`. Remember, you need directories where all modules are, _not_ directories that modules themselves set up for their organization. So `File/` should not be there, you stop with `/perl5`. – zdim Jan 19 '17 at 21:36
  • See [this post](http://stackoverflow.com/questions/2526804/how-is-perls-inc-constructed-aka-what-are-all-the-ways-of-affecting-where-pe), which is meant as a "_comprehensive "@INC" FAQ-type post_". I think that it should clarify most, if not all, of it. Out of its links [this post](http://stackoverflow.com/questions/2526520/how-does-a-perl-program-know-where-to-find-the-file-containing-perl-module-it-use) may be particularly useful. – zdim Jan 19 '17 at 21:59
  • Please let me know if I should summarize these comments in an answer. (I hope that comments and links are good enough though, since there already are many posts on this around SO.) – zdim Jan 20 '17 at 07:16
  • I would really like to solve this issue. I know that `Statistics::R` is in /usr/local/share/perl5/Statistics/R.pm, however, when I declare: `use lib '/usr/local/share/perl5'; use Statistics::R;` in Perl script. It can't locate the package. – user3781528 Feb 20 '17 at 18:09
  • That seems strange. I can't see anything wrong with the code in this last comment -- it seems that it should work. There is probably some little detail missing somewhere. I will post a bare-bones, simplest and complete working example of how to do it and will let you know (can't do it right now). Did you ever get `File::Find::Rule` to work, like we talked above and in comments on your other question? – zdim Feb 20 '17 at 19:12
  • It seems to be the same problems with most of the modules installed by the administrator of the server. However, he is not available to answer questions. :) – user3781528 Feb 20 '17 at 19:40
  • Sorry :( So the `File::Find::Rule` doesn't work either? Can you confirm _postively_ that these modules are where you expect them to be? Can there be other directories after `perl5`, like `.../perl5/lib/perl5/Statistics/R.pm`? (If yes, try to include it all up to `Statistics`.) If not, what does `ls -l /use/local/share/perl5/Statistics/*` show? or `ls -l /use/local/share/perl5/File::Find::Rule.pm`? Does `perldoc -l File::Find::Rule` give anything? Can there be issues with permissions? See whether dirs in `ls -ld /usr/local/share/perl5/*` are readable and executable by others. – zdim Feb 20 '17 at 19:59
  • There needs to be `/usr/...` above, NOT `/use/...`. Sorry – zdim Feb 20 '17 at 20:34
  • Yes, `perldoc -l File::Find::Rule /usr/local/share/perl5/File/Find/Rule.pm` and `perldoc -l Statistics::R /usr/local/share/perl5/Statistics/R.pm` ]$ ls -l /usr/local/share/perl5/Statistics/* -r--r--r--. 1 root root 22662 Oct 19 2015 /usr/local/share/perl5/Statistics/R.pm /usr/local/share/perl5/Statistics/R: total 12 -r--r--r--. 1 root root 3279 Aug 19 2014 Legacy.pm -r--r--r--. 1 root root 4155 Dec 18 2013 Win32.pm – user3781528 Feb 20 '17 at 22:08
  • Ah, that may explain it. The `perldoc -l` command shows that Perl _can_ find them. But those directories have to be _executable_ (`x`) by users of the module, not only readable (`r`). So `ls -ld /usr/local/share/perl5/` needs to show `drwxr-xr-x`. If the dirs aren't "executable" then you can't chdir there, and software cannot use what is inside. Since you are the root (right?) can you change those? Like `chmod go+x /usr/local/share/perl5`? Here it is on my system (I'm not root): `ls -ld /usr/lib64/perl5` gives `drwxr-xr-x. 50 root root 4096 [...]` – zdim Feb 20 '17 at 22:15
  • Note, the _directories_ need to be executable, not the files inside. – zdim Feb 20 '17 at 22:18
  • Find a location which works (I think you mentioned `/usr/share/perl5/`) and look at permissions on those directories, by `ls -ld dirname`. This applies to all subdirectories as well. – zdim Feb 20 '17 at 22:19
  • Hang on, I see now that none of those shown were listing of directories (but only of files). What does `ls -ld /usr/local/share/perl5` show? This directory is the one that should give `drwxr-xr-x` – zdim Feb 20 '17 at 22:40
  • Let me know if these permission suggestions don't solve it, I will then post a full example that you can set up and run to see how this works. The only question here is whether all directories have `drwxr-xr-x` permissions, so, both `r` (read) and `x` (execute), for "_owner_" (fields 2,3,4), "_group_" (next three), and "_other_" (last three). Of course, the owner also has `w` ("_write_"), they can change things. You can see that for directories by `ls -ld dirname`. Also note that "_group_" and "_other_" should strictly **not have `w` (_write_) permission**! – zdim Feb 22 '17 at 00:25
  • Here is what is returned: ls -ld /usr/local/share/perl5 drwxr-xr-x. 18 root root 4096 Nov 30 09:27 /usr/local/share/perl5. Normally, I don't log in as root. I only use `sudo` to install modules. With my normal login not sudo: chmod go+x /usr/local/share/perl5 chmod: changing permissions of ‘/usr/local/share/perl5’: Operation not permitted. thanks – user3781528 Feb 22 '17 at 13:53
  • OK, so that is good, you want that (`drwxr-xr-x`). You don't need to `chmod` it (yes, you'd need to be the owner for that, root in this case). I'll write something up and will let you know. But please also check `ls -ld /usr/local/share/perl5/File` and `ls -ld /usr/local/share/perl5/File/Find`. These directories should also have `drwxr-xr-x`. The same for `Statistics`. – zdim Feb 22 '17 at 17:45
  • ls -ld /usr/local/share/perl5/File and ls -ld /usr/local/share/perl5/File/Find also returned drwxr-xr-x. 3 root root 31 Nov 30 09:27. Thanks – user3781528 Feb 22 '17 at 20:04
  • Where you able to figure out the problem? thanks – user3781528 Feb 28 '17 at 22:34
  • No, not without access. What I'll do is post here a full working example of a script that uses a module at a non-system location (and the module), with all details and alternate ways of setting it up. Then you copy that (it should work, and if it doesn't we'll see the problem), and then with that on hand hopefully you can see what is different on your system. I hope that I'll be able to do that tonight. It's been busy ... – zdim Feb 28 '17 at 23:34
  • The answer I posted is so that there is one concrete working example for you. It's _exactly_ the same as when you use those modules -- just the path is different. Also, for this example you can actually write all files yourself so it should just work. Then you'll have that to use a template -- compare the non-working one bit by bit to this. Once you get to try please let me know. – zdim Mar 02 '17 at 00:41
  • I've removed my answer since this has been dormant for a while now and nobody found it useful. Let me if know if it is of some use for you and I will "undelete" it. – zdim Apr 07 '17 at 19:39

0 Answers0