Re: iterate over the use-d modules

[email protected] (Luca Ferrari) Wed, 2 Oct 2024 10:27:43 +0200
Newsgroups perl.beginners
Message-ID <CAKoxK+44RsX15FHrcnygb+3VRVBNccxMnBQNVFarE15nGow_Tg@mail.gmail.com>
Ciao Andy,

On Tue, Oct 1, 2024 at 5:31=E2=80=AFPM Andy Bach <[email protected]> wrote:
>
> Look at perldoc for "require" but I believe what you want is @INC in plac=
e of your @used.  Hmm, maybe not
> % perl -E 'use strict; say  for ( @INC );'

% perl -MData::Dumper -E 'say Dumper %INC;'
$VAR1 =3D 'builtin.pm';
$VAR2 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/builtin.p=
m';
$VAR3 =3D 'strict.pm';
$VAR4 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/strict.pm=
';
$VAR5 =3D 'warnings/register.pm';
$VAR6 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/warnings/=
register.pm';
$VAR7 =3D 'overloading.pm';
$VAR8 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/overloadi=
ng.pm';
$VAR9 =3D 'warnings.pm';
$VAR10 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/warnings=
.pm';
$VAR11 =3D 'Carp.pm';
$VAR12 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/Carp.pm'=
;
$VAR13 =3D 'bytes.pm';
$VAR14 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/bytes.pm=
';
$VAR15 =3D 'Exporter.pm';
$VAR16 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/Exporter=
.pm';
$VAR17 =3D 'Data/Dumper.pm';
$VAR18 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/x86_64-l=
inux/Data/Dumper.pm';
$VAR19 =3D 'constant.pm';
$VAR20 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/constant=
.pm';
$VAR21 =3D 'feature.pm';
$VAR22 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/feature.=
pm';
$VAR23 =3D 'XSLoader.pm';
$VAR24 =3D '/home/luca/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/XSLoader=
.pm';


However, this does not provide me a module name in the relative form
Foo::BAR, rather in Foo/BAR.pm, and also provides me much more stuff
(e.g., modules I've not explicitly loaded).
I'm not sure of, but I think Perl will know if a module has been
explicity loaded since if you try to do something like 'A::B->new' it
can complain that 'A::B' has not been loaded.

Luca