0

I have a standalone Perl module that I want to use, however I cannot get 'set lib' to work. What am I doing wrong?

I am working off the terminal in Mac OS and the module is located in a folder on my desktop /Users/John/Desktop/HT/Conlang.

#! perl -w

package HT::Conlang::S17;

use strict;
use vars qw($VERSION @EXPORT_OK);
use base 'Exporter';
use lib '/Users/John/Desktop/HT/Conlang';
use HT::Conlang::S17;

How can I get this to work?

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • that doesn't seem to be working. when i try to run the module in the terminal nothing happens. – Stackman Apr 21 '17 at 03:00
  • 2
    OK .. what is (not) wrong here? (1) What is the exact error you get? (2) Why do you have `use HT::Conlang::S17;` _inside_ that very package? (3) The directory looks "suspiciously" close to the location the module is in -- is this module in a directory just above the one you are trying to set? – zdim Apr 21 '17 at 03:32

1 Answers1

2

Problem #1. It doesn't make sense to use use lib inside a module. It belongs in scripts. And even then, if it's an absolute path (as opposed to a path relative to $FindBin::RealBin), it's far better to set env var PERL5LIB than to use use lib.

Problem #2. If your module uses package HT::Conlang::S17, it should be loaded using use HT::Conlang::S17;, which means Perl will search for HT/Conlang/S17.pm, so the entry to add to @INC should be /Users/John/Desktop.

Problem #3. /Users/John/Desktop contains more than just Perl modules. You should have a directory dedicates to being a Perl library directory.


Solution, part 1. Move /Users/John/Desktop/HT to /Users/John/perl5/lib/HT.

Solution, part 2. Have your login process add /Users/John/perl5/lib to the env var PERL5LIB.

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Solution 1: I copy pasted the folder from my desktop to the perl5 lib Solution 2: I have no idea how to do this, what exactly should I enter to do this? – Stackman Apr 21 '17 at 05:51
  • What OS are you using? OS/X? I don't know. – ikegami Apr 21 '17 at 06:00
  • ...but Google says [Setting environment variables in OS X?](http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x) – ikegami Apr 21 '17 at 07:24
  • I've gone ahead and done all of that. The program still won't work. – Stackman Apr 26 '17 at 02:42
  • Provide the output of the following: `printf "PERL5LIB: %s" "$PERL5LIB" ; ls -ld /Users /Users/John /Users/John/perl5 /Users/John/perl5/lib /Users/John/perl5/lib/HT /Users/John/perl5/lib/HT/Conlang /Users/John/perl5/lib/HT/Conlang/S17.pm ; perl -e'use HT::Conlang::S17;'` – ikegami Apr 26 '17 at 02:55