====== Finding external dependencies in a Perl project ====== Assume you have a project implemented in Perl and you want to find external dependencies for preparing a CPAN package for example. This is a handy set of commands that allow you to do just that. ===== Finding external dependencies ===== To do this, we first need to find which packages are used by the project. for i in `find . -name *.p* -print`; do cat $i | grep -E '^use.*;'; done | cut -d" " -f2 | sed 's/()//g' | sed 's/;//g' | sed 's/ //g' | sort -u > used Then, we need to find which packages are declared/exported by the project. for i in `find . -name *.p* -print`; do cat $i | grep -E '^package.*;'; done | cut -d" " -f2 | sed 's/;//g' | sort -u > declared The packages that are used but not exported by our project are the external dependencies. This is how we find them. while read line ; do grep -q $line declared; if ! [ $? -eq 0 ]; then echo "$line"; fi ; done < used //Note : If your edit your perl files under windows, you may want to filter out DOS/Windows CR/LF end of lines.// {{tag>unix howto}}