Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

RE: Detecting modules in use?

by Adam (Vicar)
on Oct 31, 2000 at 02:03 UTC ( #39202=note: print w/replies, xml ) Need Help??

in reply to Detecting modules in use?

Collecting the better-late-then-never award:

Look for the module in the %INC associative array. According to the docs for require (and use just calls require in a BEGIN block) every module that gets 'used' gets its name put into this hash, where the key is the file name, and the value is the 'real path' to the file. So the answer is:

if( not exists $INC{DBI} ) { require DBI; }
Update: Noticing that KM actually gave this answer here, I return the "better-late-then-never" award. Sigh.

Replies are listed 'Best First'.
RE: RE: Detecting modules in use?
by dchetlin (Friar) on Oct 31, 2000 at 02:45 UTC
    Also, require does that automatically. The manpage has this snippet:

    Has semantics similar to the following subroutine: sub require { my($filename) = @_; return 1 if $INC{$filename}; my($realfilename,$result); ITER: { foreach $prefix (@INC) { $realfilename = "$prefix/$filename"; if (-f $realfilename) { $INC{$filename} = $realfilename; $result = do $realfilename; last ITER; } } die "Can't find $filename in \@INC"; } delete $INC{$filename} if $@ || !$result; die $@ if $@; die "$filename did not return true value" unless $result; return $result; }


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://39202]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-01-22 04:55 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (186 votes). Check out past polls.