Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

From the command line, how could I strip a Perl program of all of its white space, so that the file now contains only Perl code in one solid block (ie, one long string of code)? Whether it compiles or not is not important... Thanks.

Note: Any comments or POD should also be removed, along with the white space.

  • Comment on Turning a script into a solid block of code

Replies are listed 'Best First'.
Re: Turning a script into a solid block of code
by chromatic (Archbishop) on Nov 16, 2007 at 23:03 UTC
Re: Turning a script into a solid block of code
by jbert (Priest) on Nov 16, 2007 at 23:32 UTC
    I'm interested to know what application such a lossy conversion is useful for. I can't think of anything you could do with a unpretty-not-necessarily-compilable script other than hash it for uniqueness (which you could do more usefully to the unmangled script).

    Out of curiosity, could you tell us more about your purpose please?

Re: Turning a script into a solid block of code
by Anonymous Monk on Nov 16, 2007 at 21:42 UTC
    perltidy -mangle -dac -st yourprogram | tr -d '\n'
Re: Turning a script into a solid block of code
by perlfan (Parson) on Nov 16, 2007 at 21:31 UTC
    If you don't care if it runs, which it will not:
    # perl -pi -e 's/[\s\n]//g' file.pl #makes test.pl solid block of p00
    I don't know how to remove POD - maybe all lines that start with "=". If you want it to run, check out http://liraz.org/obfus.html.