I'm wondering what daily Perl usage that's even vaguely useful that I do, which could be improved upon.
Ah, of course, triple-f one-liners!
As a tool, the perl command often seems to replace a jungle of echo + egrep + cut + tr + sed + awk and whatnot.
perl -nawe
and ctrl+r (reverse i-search) in bash are good friends of mine, but after using the same one-liners a few times in a row, I usually end up converting them to tidy files with Getopt::Long
, comments and other insanities.And at some stage later, I say to myself: damnit, I should've coded this more generally, I start a recode, get distracted, solve a new problem with one-liners, and the circle of life goes on.
Do I need professional help?
2 comments:
Hey, not to be bragging (or doing shameless propaganda), but I think I wrote a module for you! :P
It's called App::Rad, and here's how to use it for your purposes:
Create a file called "myapp.pl" or whatever, with this in it:
----------8<----------
#!/usr/bin/perl
use App::Rad qw(include);
App::Rad->run();
---------->8----------
And put it in your path. Then, next time you make a nice one-liner and want to keep it, change "perl" to "myapp.pl include NAME", so this:
> perl -i -pe "s/aaa/bbb" file.txt
becomes this:
> myapp.pl include replace -i -pe "s/aaa/bbb"
it will create a "replace" command for your app so next time you want to use it you can just do:
> myapp.pl replace file.txt
you can see all available commands created by you just typing "myapp.pl" without arguments.
App::Rad has a lot of functionality built in to create command-line apps, but for your needs maybe the "include" command will suffice. It will let you store your one-liners in a reusable way - maybe even allowing you to expand and refactor them as you see fit.
If you can, please give it a try and let me know what you think. Thanks!
While the blog entry was supposed to be a bit of a whine than a request for help:
Thanks, that seems convenient for at least some of the cases.
Post a Comment