in reply to translate to one-liner

No.


(I suppose it might not actually be that hard to write something that would remove all of the newlines from a script, dealing with heredocs and tossing podstuff and comments correctly, but .... why?)

Replies are listed 'Best First'.
Re^2: translate to one-liner
by GrandFather (Saint) on May 25, 2015 at 02:06 UTC

    although handling implicit looping over contents of files passed on the command line and print etc may be a little more challenging, but as you say, "Why"?

    Perl is the programming world's equivalent of English

      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.

        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". ;-)