Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to tell if a package is loaded

by John M. Dlugosz (Monsignor)
on May 02, 2011 at 22:56 UTC ( [id://902580]=note: print w/replies, xml ) Need Help??


in reply to How to tell if a package is loaded

I think %INC will show you everything that was pulled in via use or require.

Yes, this works for me:

perl -MFile::Find -E'print join "\n", keys %INC'

Replies are listed 'Best First'.
Re^2: How to tell if a package is loaded
by tchrist (Pilgrim) on May 02, 2011 at 23:25 UTC
    If all you want to do is play with %INC, instead of actually inspecting the symbol table properly, then you might as well use the standard core module, Module::Loaded.
      What version of Perl did Module::Loaded become core in? I'm using 5.8.8 and it is not available there.
      $ perl -MModule::Loaded Can't locate Module/Loaded.pm in @INC (@INC contains: /usr/lib64/perl5 +/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5 +.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_ +64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5 +/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/li +b/perl5/5.8.8 .). BEGIN failed--compilation aborted.
        $ corelist Module::Loaded Module::Loaded was first released with perl v5.9.4
        I'm on 5.12.2.

        See also New modules

Re^2: How to tell if a package is loaded
by educated_foo (Vicar) on May 02, 2011 at 23:38 UTC
    Kind of. Remember that a file can define more than one package, e.g.
    $ echo 'package A; package B; 1' > A.pm; perl -MA -le 'print for keys +%INC' A.pm
    If you want to know if a package is defined, rather than whether a correspondingly-named file has been loaded, the OP's approach is correct.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found