in reply to Re^3: translate to one-liner
in thread translate to one-liner

Well, if you allow a little bit of "cheating":

Place the code of the original program in a Module. Wrap the main code in a subroutine. Add use Exporter qw( import ); and @EXPORT_OK=qw( the_main_subroutine ); to the module. Call as perl -MThe::Module=the_main_subroutine -e the_main_subroutine. Voila: nearly instant one-liner. To make the one-liner even shorter, use @EXPORT instead of @EXPORT_OK, then use perl -MThe::Module -e the_main_subroutine.

This is a first step to really useful modules. Reduce the main program, make more subroutines available, return values instead of printing them, and so on. You may end with a "hybrid" module that is primary useful in other programs, but has a little routine exported on demand so you also can use it from the command line, as shown above.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)