Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: translate to one-liner

by GrandFather (Saint)
on May 25, 2015 at 02:06 UTC ( [id://1127641]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^3: translate to one-liner
by j--a (Novice) on May 26, 2015 at 05:45 UTC

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1127641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found