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

Something very odd just happened. I fired up a script that I used just a few weeks ago. It calls mods:
use feature ':5.10'; use URL::Encode qw(url_encode); use Storable qw(nstore retrieve); use Date::Manip; use LWP::UserAgent; use Math::Round qw(round); use JSON::XS;
When I run the script it says Can't locate URL/Encode.pm in @INC (you may need to install the URL::Encode module). If I comment-out the second line it throws the same error for Date::Manip. I run cpan -l and there they are!

It's not that the env variable $PATH got screwed up, because if I comment-out Date::Manip too it finds the other mods. This has me scratching my head. What could explain it?

Update

I found that if I run it from the command like so perl program.pl it finds the mods. But if I run it like so program.pl it doesn't. So I'm guessing must be something wrong with the file association to *.pl. I wonder how to fix that.

Replies are listed 'Best First'.
Re: Interpreter can't find known installed mods (w10)
by afoken (Chancellor) on Aug 13, 2023 at 17:37 UTC

    Run

    perl -V

    (uppercase "V"!) and compare the listed @INC content with what you expect it to be.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      @INC: C:/Perl64/site/lib/MSWin32-x64-multi-thread C:/Perl64/site/lib C:/Perl64/lib .
      Both Date::Manip and URL::Encode are in C:/Perl64/site/lib

        I guess that you have another Perl binary lying around, and this other binary is associated with .pl files. This would explain that some modules are found (those have been installed under the other Perl binary as well, or are part of the Core like Storable).

        You can add a line to your script and compare the results of the different invocations:

        print "Perl interpreter: $^X\n";
        For grins, run this code:
        use strict; use warnings; my @paths = grep{/perl/i}split ";", $ENV{PATH}; print "$_\n" for @paths; __END__ C:\Perl64\site\bin C:\Perl64\bin
        I am also wondering if there is a 32 bit Perl in there somehow?
        That your ASSOC is not set right is an indication that something went wrong in the installation of 64 bit Perl.
Re: Interpreter can't find known installed mods (w10)
by Marshall (Canon) on Aug 13, 2023 at 18:34 UTC
    "I found that if I run it from the command like so perl program.pl it finds the mods. But if I run it like so program.pl it doesn't. So I'm guessing must be something wrong with the file association to *.pl. I wonder how to fix that."

    Here is command line way.
    Of course perl.exe has to be found in the PATH.

    C:\Users\marshall\Documents\PerlProjects>assoc /? Displays or modifies file extension associations ASSOC [.ext[=[fileType]]] .ext Specifies the file extension to associate the file type wi +th fileType Specifies the file type to associate with the file extensi +on Type ASSOC without parameters to display the current file associations +. If ASSOC is invoked with just a file extension, it displays the curren +t file association for that file extension. Specify nothing for the fil +e type and the command will delete the association for the file extensio +n. C:\Users\marshall\Documents\PerlProjects>assoc.pl .pl=Perl
Re: Interpreter can't find known installed mods (w10)
by Dallaylaen (Chaplain) on Aug 14, 2023 at 09:51 UTC

    What is the first line of the script (shebang)? It's likely that the perl executable in your path is different from the system's default - and only the one in the path has all necessary modules installed.

    I've been using #!/usr/bin/env perl as the first line for a while now - and never regretted doing so. EDIT: Sorry, this only applies to *nix-like systems and the question was about Windows.

    P.S. What OS are you using, BTW?

        Thanks. It was in the subject all the time. I need new glasses :-/