in reply to Re^4: Is require still required?
in thread Is require still required?

This is all stated in the documentation for require, inclusive the role of %INC:

if (exists $INC{$filename}) { return 1 if $INC{$filename}; croak "Compilation failed in require"; }

To import a fle more than once you have to delete from %INC of course.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^6: Is require still required?
by choroba (Cardinal) on Feb 03, 2024 at 20:04 UTC
    > To import a fle more than once you have to delete from %INC of course.

    Or use a different path to it (I've seen this in production, don't ask).

    My.pm:

    package My; use warnings; use strict; our $counter //= 10; ++$counter

    script.pl

    #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use lib './'; say require My; # 11 say require 'My.pm'; # In %INC, returns 1. say require './My.pm'; # Not in %INC, thus 12!

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      > (I've seen this in production, don't ask).

      Yes, because keys in %INC are the paths.

      Edit
      But if I wanted to reload the required file, I'd rather use an explicit %INC hook doing it explicitly without leaving a key at all.

      Though I have trouble imagining a use case...

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery