Friday 9 April 2010

one-liner tip: aliases

When it comes to bending the system into doing what we want in a quick-and-dirty fashion, nothing beats a Perl one-liner. There are several great tips and talks on one-liners, but they usually focus on Perl itself. Well, turns out I use one liners often enough that I became lazy even to write "perl -...". So I remembered the good old 'alias' shell command and put these in the end of my .bashrc file:


alias pe='perl -E'
alias ppe='perl -pE'
alias pne='perl -nE'
alias pipe='perl -i -pE'
alias pine='perl -i -nE'


that alone saves me a whole lot of typing over the week :)


> pe 'say q[hello, lazyness!]'
> hello, lazyness!

It's also pretty easy to remember, since you just type 'p' for 'perl', followed by the main flags your one-liner has. Oh, and of course you also can pre-load your favorite modules, doing things like:


alias pe='perl -MData::Dumper -lE'


That's it, hope you enjoy it :)