Yes, this is possible, but also, that way lies madness. If you go down that road, you will make things much harder for you, and you will have to debug lots of weird errors. You are much better served by re-installing a fresh copy of all modules with your current Perl, and keeping your modules (say) in a cpanfile so you can reinstall them quickly whenever you move to a new version.

Perl will not reload a module if it has already been loaded. A first, horrible approach is to manually pre-load all the modules you want from the appropriate directories:

use 5.020; use feature 'experimental::signatures'; no warnings 'experimental::signatures'; sub preload_module( $base_dir, $modulename ) { my $final_name = $modulename; $final_name =~ s!::!/!g; require "$base_dir/$final_name.pm"; } BEGIN { preload_module('/some/perl5/dir', 'List::Util' ); preload_module('/some/perl5/dir', 'Scalar::Util' ); preload_module('/some/other/perl5/dir', 'Another::Module' ); } use List::Util 'reduce';

An even more horrible way is to set up a hook in @INC which looks at the file to be loaded and chooses the correct one:

use 5.020; use feature 'experimental::signatures'; no warnings 'experimental::signatures'; my %module_map = ( 'List/Util.pm' => '/some/path/to/perl/modules', 'Scalar/Util.pm' => '/some/other/path/to/perl/modules', ); sub find_correct_module( $self, $module_file ) { my $real_module = $module_map{ $module_file } // $module_file; open my $fh, '<', $real_module or croak $!; return $fh } BEGIN { unshift @INC, \&find_correct_module; }

This will be even harder to debug but allows you to have deep dependencies automatically resolved without preloading modules.

Again, my advice is to do a fresh start and keep a list of all modules you need, and use local::lib and to install all dependencies below a directory separate from the system Perl directory.


In reply to Re^6: help with "symbol lookup error" message by Corion
in thread help with "symbol lookup error" message by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.