July 2012 Archives

Integrating perlcritic and vim

Naturally, you'll need to season this to taste, but here's how I've now integrated perlcritic and vim, making it easy to jump to specific errors.

I've previously written about using the Vi::QuickFix module. It takes advantage of vim's quickfix commands.

First, drop this into your .vimrc:

" quickfix for Perl error formats
set errorformat+=%m\ at\ %f\ line\ %l\.
set errorformat+=%m\ at\ %f\ line\ %l

I also have the following mapping:

noremap ,c :!time perlc --critic %<cr>

It's the perlc hack which makes all of this work.

Finding Unused Subroutines

Posting this here to help me remember this.

I have to do a bit of work cleaning up some old code and I wrote this quick shell script to find possibly unused subroutines.

#!/bin/bash

tempfile=/tmp/$$allsubs.txt

ack '^\s*sub\s+(\w+)\b' lib |     \
    awk '/sub (\w*)/ { print $2 }' | \
    cut -d'(' -f1 |                  \
    sort |                           \
    uniq > $tempfile

for sub in $(cat $tempfile); do
    if [[ $(expr `git grep -E "\<$sub\>" |wc -l`) == 1 ]]; then
        echo $sub
    fi
done

rm $tempfile

My bash skills are awful (see above), but I've already found 25 subroutines that can probably be deleted. I say "probably" because all have to be investigated.

About Ovid

user-pic Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.