Zip your Perl one-liners
Paraphrasing Larry Wall, the trouble with the Perl one-liners is that they doesn't necessarily fit 80 columns.
There are so many flags to pass to perl
, like STDIO encoding, include paths, module imports... And parsing multiple structured files through one-liner can be painful.
Thankfully, there is App::p - Steroids for your perl one-liners.
It does few things, but does it really well. It automates lazy dependency loading (no need to type -M
anymore!) and adds several convenient shortcuts for commonly used functions.
So, brace yourselves, let's use Perl as a CLI date calculator with familiar syntax:
$ p 'S DateTime->today->add(days=>92)->ymd'
2013-03-31
As you see, there is no need to declare DateTime (it wasn't pre-declared, either!)
S
is a shortcut for say
. There are several others:
- r/w - read/write files via File::Slurp;
- jd/jl - dump/load via JSON::XS;
- xd/xl - dump/load via XML::Hash::LX;
- yd/yl - dump/load via YAML;
- dd from Data::Dump;
- get,head,getprint,getstore,mirror from LWP::Simple;
- sum,first,min,max,zip,uniq,any,all,none ... all from List::AllUtils.
The script os very simple, if you miss any idiosyncrasy of yours, don't hesitate to fork it and customize it :)