Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: help with "symbol lookup error" message

by hippo (Bishop)
on Feb 02, 2023 at 11:58 UTC ( #11150090=note: print w/replies, xml ) Need Help??


in reply to Re^3: help with "symbol lookup error" message
in thread help with "symbol lookup error" message

Is File::Copy versioned separately from Perl itself? When I look at the CPAN page it looks like File::Copy shares the version number of the perl distribution it is included with

File::Copy is a core module which means that it is bundled and shipped with Perl. However, the core modules do not share their version numbers with the corresponding Perl version. The page you linked contains both the version number of Perl (in the crumbtrail at the top of the main div) and the different version number for File::Copy (at the top of the left margin). For core modules, Perl itself is the dist but each contained module is versioned separately.

So what's happening is that in perl 5.34.0 and earlier, a module that is included with Perl by default (File::Copy) is calling a module that is not (List::Util)? And then perl 5.36 removed this dependency?

Yes, with the exception that List::Util is a core module too. See modules for the full list of core modules.


🦛

  • Comment on Re^4: help with "symbol lookup error" message

Replies are listed 'Best First'.
Re^5: help with "symbol lookup error" message
by Special_K (Monk) on Feb 03, 2023 at 20:28 UTC

    So in my example, which uses 5.20.0, File::Copy is calling List::Util, but is finding the version installed at /home/user_foo/perl_modules/lib/perl5, rather than the version installed at a location corresponding to (and compatible with) 5.20.0. Is that correct? Is it possible to tell perl to use one path for a specific module but use another path (or set of paths) for other modules?

      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.

        > and keeping your modules (say) in a cpanfile so you can reinstall them quickly whenever you move to a new version.


        This is the first time I've heard the term cpanfile, so I read this page:
        https://metacpan.org/dist/Module-CPANfile/view/lib/cpanfile.pod

        and it seems I could just maintain this file by having a requires $module line for each module I want to maintain. Then when a new version of perl is installed, I can just create a new directory, copy the cpanfile, and then run cpanm to reinstall all modules in that local directory using the new version of perl. Is that correct?

        If I do that, is a record created anywhere in that directory indicating what version of perl was used to do the installation, or do I need to maintain that myself via directory naming conventions and/or README files?

        Also does a new directory need to be created for each version of perl no matter how minor the update? For example, if I am currently using 5.36 and a 5.36.1 is released, do I need to reinstall all modules using 5.36.1 or can I wait for a larger update, e.g. 5.37?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2023-03-25 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (63 votes). Check out past polls.

    Notices?