How to: Find all modules used in a tree

On the perl-qa list tonight, we were discussing how best to find all the modules used in a source tree. To do the job right, you'd have to run the code and then look at the %INC:: hash, which shows the paths of all modules loaded. The low-tech and usually-good-enough solutions we came up with use ack:

$ ack -h '^use\s+(\w+(?:::\w+)*).*' --output=\$1 | sort -u

Thanks to Andy Armstrong for coming up with a better regex than mine, which assumed that the use statement would necessarily end with a semicolon.

Categories:

1 Comments

kbrint said:

Don't forget about "require"

/^(?:require|use)\s+(\w+(?:::\w+)*).*/

Leave a comment

About this Entry

This page contains a single entry by Andy Lester published on February 7, 2008 8:37 PM.

Getting lines from a website with GET and ack was the previous entry in this blog.

The perils of Perl 5's indirect object syntax is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Other Perl Sites

Other Swell Blogs

  • geek2geek: An ongoing analysis of how geeks communicate, how we fail and how to fix it.