📜 ⬆️ ⬇️

Search by installed modules.

The first thing I learned in the process of learning programming is that you don’t have to reinvent the wheel. Much of what you need has already been written and the ability to find and glue the necessary parts is no less important than the ability to write code. Of course to write the most interesting but now is not about that :)

Perl is the blood of the Internet and CPAN is a very important part of this language.
At some point, I needed one of the XML modules. Since my desktop is Debian Lenny (almost namesake), I decided to do it in a debian-way and installed it via apt. The module was installed along with all dependencies and then I realized that I did not pay attention to what he installed. Having decided to check the already installed modules, I came across a certain problem, it turned out that it was not so easy to do this with a simple command.

Perhaps it will be useful to someone. The File :: Find module is required.
')
 #!  / usr / bin / perl -l
 use strict;
 use warnings;
 use File :: Find :: Rule;

 my @seen;

 for my $ path (@INC) {
         for my $ file (File :: Find :: Rule-> name ('*. pm') -> in ($ path)) {
                 my $ module = substr ($ file, length ($ path) +1);  
                 $ module = ~ s / .pm $ //;  # remove end files from titles
                 $ module = ~ s {[\\ /]} {::} g;  # change / \ to :: for readability.
                 push (@seen, $ module); 
         }
 }
 print join ("\ n", (sort {lc ($ a) cmp lc ($ b)} @seen)), "\ n";  # sort by name and print

 Of course you can paypit and show modules on wildcard.  For example, suppose the script name is: findmodule.pl.

 root @ debian: ~ # perl findmodule.pl |  grep -i snmp
 SNMP_Session
 SNMP_util


Source: https://habr.com/ru/post/54423/


All Articles