for code in $(find . -type f -name '*.p[ml]'); do perl -c "$code"; done

Check syntax of all Perl modules or scripts underneath the current directory

Finds all *.p[ml]-files and runs a perl -c on them, checking whether Perl thinks they are syntactically correct
Sample Output
./ syntax OK
./bar/ syntax OK

By: udog
2010-05-29 23:26:40

These Might Interest You

  • Uses the PHP binary to check the syntax of all .php files in or below the current working directory. Really handy for doing that last minute check before you commit code to the repository. Show Sample Output

    find . -name "*.php" -exec php -l {} \; | sed -e "/^No syntax/d"
    TomNomNom · 2009-02-10 09:14:25 0
  • Check all bash scripts in current dir for syntax errors WITHOUT running them. Show Sample Output

    find . -name '*.sh' -exec bash -n {} \;
    tsener · 2014-01-17 16:20:36 0
  • Removes all *.swp files underneath the current directory. Replace "*.swp" with your file pattern(s).

    find . -name \*.swp -type f -delete
    ashwinkumark · 2013-01-19 07:38:03 0
  • This will add a perl POD stub above each method in all modules found recursively in your current directory. The stub will look like: =head2 method_name =cut sub method_name { ...

    find . -type file -name '*.pm' | xargs perl -p -i -e 'BEGIN{undef $/;} s/([;}])\s*\nsub (\w+)/$1\n\n=head2 $2\n\n=cut\n\nsub $2/g'
    xevo · 2014-11-05 18:19:37 0
  • Lists all the modules that were installed the "proper way". It also uses Perl 5.10(or higher)'s say command for less typing. Show Sample Output

    perl -MExtUtils::Installed -E 'say for ExtUtils::Installed->new()->modules()'
    kimmel · 2011-11-16 17:26:47 0
  • IMVHO if you are using cpan to install perl modules you are doing it wrong. Show Sample Output

    dpkg-query -W | grep perl
    unixmonkey10924 · 2010-07-20 16:14:04 1

What Others Think

Faster with find -type f -name '*.p[ml]' -exec perl -c {} \;
rocku · 416 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: