cristofayre has asked for the wisdom of the Perl Monks concerning the following question:

I installed Strawberry, and installed a module via CPAN. The latter stored the module in "C:/Users/My_Name/l5/lib/perl5" However,when I run the script, it cannot find it as @INC only contains "strawberry/perl/site", "strawberry/perl/lib" and "strawberry/vendor/lib"

I THINK I could add "use lib 'path_to_perl5' in each script ... but that could cause confusion if I forget to remove it before uploading to the online server.

So is there a way - on Windows7 - to add the path PERMANTELY to the @INC array?, (similar to the way you can add items to the Apache vhost file)

Replies are listed 'Best First'.
Re: Strawberry, CPAN and PERL5
by Corion (Patriarch) on Aug 31, 2019 at 08:47 UTC

    Usually Strawberry Perl does not put modules from CPAN into a directory in your user directory. Did you maybe have an older installation of Perl set up to do that?

    See perlrun on the PERL5LIB variable and maybe local::lib. Most likely you had local::lib set up from an older version of Perl there. My recommendation is to at least delete everything from the old installation there.

Re: Strawberry, CPAN and PERL5
by jcb (Parson) on Aug 31, 2019 at 21:39 UTC

    I seem to remember that there is some kind of relocation step that is supposed to be done as part of a Strawberry Perl installation? Presumably that relocation step changes "strawberry/" in the various paths to wherever Strawberry Perl was actually installed. Read the Strawberry Perl installation instructions very carefully. It looks like you missed a step.

Re: Strawberry, CPAN and PERL5
by perl-diddler (Chaplain) on Sep 02, 2019 at 05:15 UTC
    First off, I'm sorta guessing, but l5, sounds like an abbreviation for /usr/lib/perl(5)/(site|local)/.... Since in a normal install of Win7 you are your own 'site'. In regards to SBperl not putting thing under neat your own User dir, where would you put your 'local site' modules dir that were added by the user that were in a personal version of SBperl? If you were compiling for a company, you might already know how to build your own perl, but for an individual?

    Have you looked at %Config to see what has the path under your home dir? (i.e. is it the SITE paths?) -- sounds like not or it should have found them at run time.

    I just dumped my config with:

    alias tperl='perl -I/home/myuserid/bin/lib -we'\''use strict; use P;' tperl use Config; use Data::Dumper; my $dmp = Data::Dumper->new([\%Config], [ "Config" ]); $dmp->Indent(1)->Deepcopy(0)->Sortkeys(1)->Deparse(1)->Purity(1)->Quot +ekeys(0); printf "%s\n", $dmp->Dump;'
    Might also want to look at your CPAN config for clues: more ~/.cpan/CPAN/MyConfig.pm

    The other thing to do would be to create a 'lib' dir under your executable and add the relative path at runtime:

    use FindBin qw($Bin); $FindBin::Bin =~ s{/bin/lib/?$}{/bin}; use lib ($FindBin::Bin . "/lib", $ENV{HOME} . "/bin/lib");
    For conditional compilation, I used something like:
    #!/usr/bin/perl use warnings; use strict; use P; use parent 'Switches'; ## example of a PERL compile-time constant ## based on a command line argument "-NODEBUG" ## using 'Switches' & BEGIN ## to run, place "-DNODEBUG" on the command line. (law) BEGIN { Switches->process_options({DNODEBUG => { act => [ sub { eval '# line '.__LINE__.' "'.__FILE__.'" use constant "_NODEBUG_"=>1;'; $@ && P::Pe("eval: %s\n", $@); } ], } }, \@ARGV); eval 'use constant _NODEBUG_ => undef;' unless *main::_NODEBUG_{CODE +}; } sub declared ($) { use constant 1.01; # note: needed for "declared", belo +w my ($name, $pkg) = (shift, caller); # prepend module name (must be a full-name) $name = q(main) . $name if '::' eq substr $name,0,2; # use caller pkg if needed my $full_name = 0 <= index($name,'::') ? $name : $pkg.'::'.$name; $constant::declared{$full_name}; } P "_NODEBUG_ is a %s %s", declared(q(_NODEBUG_)) ? "constant" : "sub" +, P "and is %s", _NODEBUG_ ? "TRUE (devel checks disabled)." : "FALSE (devel checks enabled)."
    Switches will check if "-DNODEBUG" is on the command line, if so, it will call the first eval, otherwise the end.

    The constant created (_NODEBUG_) becomes a compile time constant that will be either '1' or 'undef'.

    When working locally, create an alias or batch file to run your program with the -DNODEBUG switch. You can still take it out later, but this way if you upload your code w/o removing your custom code, it won't get activated.

    Since _NODEBUG_ is a compile time constant, perl should either not include or include your debug code at runtime.

    Those were just a few things I thought of off the top of my head. Hope it helps!

Re: Strawberry, CPAN and PERL5
by cristofayre (Sexton) on Aug 31, 2019 at 08:46 UTC

    I MAY have just found a way around the problem, and that is to use $^0; this tells you the operating system. So ...

    $OS=$^0;

    use lib "path_to_perl5" if $OS == 'MSWin32'

    IN THEORY, on Windows, it will use the revised perl5 / CPAN location, but when run on Unix server,it will bypass this line as the IF will be incorrect. (Not yet tried)

      That condition will always be true (with a warning). To compare strings, you'll need eq, not ==.


      Enjoy, Have FUN! H.Merijn
      ... a way around the problem ...
      ...
      use lib "path_to_perl5" if $OS == 'MSWin32'

      Others have correctly commented that the problem described in the OP is much more basic than conditional compilation (update: and seems to be essentially a system configuration problem). In addition to | Be that as it may, beyond the comparison operator problem pointed out by Tux, a use statement is executed at compile-time, but a
          if (condition) { ... }
      or
          ... ifcondition;
      statement executes at run-time. So the effect of

      c:\@Work\Perl\monks>perl -wMstrict -le "if ('night' eq 'day') { use constant FOO => 42; } ;; print FOO; " 42
      is not what you expect.

      Consider the if pragma for use in cases like this — but not in this particular case!

      c:\@Work\Perl\monks>perl -wMstrict -le "use if 'night' eq 'day', constant => FOO => 42; ;; print FOO; " Name "main::FOO" used only once: possible typo at -e line 1. print() on unopened filehandle FOO at -e line 1.

      Update: Made some changes in the first paragraph to try to clarify the intent and focus of this reply.


      Give a man a fish:  <%-{-{-{-<

      No. Fix you're config issue. As first step post the output of
      perl -V

        Are you sure you have uninstalled Perl5 prior to installing Strawberry ?