Apologies Monks.
I should have elaborated, this was/is not by any means critical. There is no need, just my own esoteric curiosity. I've been playing around with 'the problem' for a bit now and wondering if it was a thing which had already been handled. Every search gave results for the converse situation of turning a one-liner into a program, thus my desire to get more insight.
Thank you for your attention.
| [reply] |
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". ;-)
| [reply] [d/l] [select] |