in reply to pmpath

be careful with code like this, as you've left open the possibility that unintended code will run on your system.

when you require a module, it calls the module's import method at runtime. this method can be defined to almost anything within the module. although in many cases only the default import method is used, it is possible to have a good bit of code there. for an example, look at the POSIX module, which uses import (and AUTOLOADing, but that's a different story.)

i'd suggest using File::Find and regular expressions to do this in a development environment with a shared @INC. you can never be too careful.

~Particle

Replies are listed 'Best First'.
(sacked) Re: Re: pmpath
by sacked (Hermit) on Jan 24, 2002 at 08:43 UTC
    require loads a module at runtime, but it does not call the module's import function. From `perldoc -f require':
    ...demands that a library file be included if it hasn't already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of `eval'.
    And from `perldoc -f use':
    Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to BEGIN { require Module; import Module LIST; }

    --sacked
      right you are!

      my mistake. now where on earth did i read otherwise...?

      sorry for the disinformation, jbisbee!

      ~Particle

        No problem. I posted it to get feelback and its been very informative (regardless of right or wrong). I just find 'pmpath' helpful to quickly compare module versions on different servers and environment. For example our personal dev boxes here at work are all linux, while I main group dev box is Solaris. It's cool do run a quick check to compare their locations and version on multiple servers running differnent operating systems.

        -biz

      True, it doesn't call the import() method as use would, but it does run any code in the module up to the "1;" (or similar) return-code. In other words, if the module has any initialization code (including BEGIN blocks, and in 5.6 onward CHECK and INIT blocks), that code will be executed by the script you are demonstrating.

      You really are better-served by combining File::Find with the pre-defined @INC array as the list of directories to search over.

      --rjray