Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Compiling Perl?

by Anonymous Monk
on Apr 29, 2000 at 00:00 UTC ( #9628=perlquestion: print w/replies, xml ) Need Help??

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

I want to a give a copy of a script I have written to a friend of a friend. I don't particularly want him to have the source code.

Recently I have investigated many ways of compiling Perl code - using 'Perl2Exe', which refuses to compile in URI and LWP modules (essential for my script) and the 'perlcc' program that comes with ActivePerl. Perlcc produced a 33,000 line C program from 500 line Perl program, and after struggling with GCC attempting to compile it, I finally figured out how to tell GCC to look in /foo/bar/ for header files. I'm still missing one header and I get compiler errors anyway. So, I've now given up on compiling into C too. I don't like C anyway - that's why I use Perl!

I'm on Win32 and I really want to get this compiled. Any suggestions would be greatly appreiciated.

Replies are listed 'Best First'.
Re: Compiling Perl?
by chromatic (Archbishop) on Apr 29, 2000 at 20:44 UTC
    There is a CPAN module called Filter (as the Anonymous Monk notes, jogging my memory) which provides the useful Filter::Util::Exec module. What you can do with that is specify a filter to be run on your program before it is executed.

    Suppose you were to finish the program you want to obfuscate, then run it through a compression/encryption scheme. You could write a small loader using Filter::Util::Exec that would uncompress/unencrypt the supplied code. You might even implement this as a separate program, and compile that.

    Another option from the same family is Filter::decrypt, which may be more suited for this. (I've not seen it used, though.)

    Finally, there is always the Camel-recommended dump-undump method. I've never seen that used.

Re: Compiling Perl?
by SuperCruncher (Pilgrim) on Apr 29, 2000 at 01:02 UTC
    (BTW I wrote the message under AM as I couldn't find my login) I do agree with open source - but I'm not one of the "Everything must be open" brigade.

    He could potentially use the script to compete with me, among other things. He may also modify it and not keep my details in it. That would really annoy me.

    I don't want him to have the source! Is that unreasonable (note: rhetorical question)?

      Why are you worried about competition? If you are afraid someone is going to steal your ideas, get over it. If it was worth something you would either patent it or not share it. If you've written something you think is comercially viable, then I can see why you are worried but I don't see why you are giving it away.

      Oh well, the way to do this is to follow the instructions on embedding a perl interpreter into a c program, and follow that route. I've seen numerous accounts on how to do this, in fact I think there is a link in the Monk Library.

      And yes, C is going to need many more lines of code because C does not handle text processing very well. This doesn't make it a bad language. I'm all for knowing several languages.

        Why are you worried about competition?
        If you set up a shop, do you worry about competition? Of course. I am using this script to set up a web site and I know that the person is considering setting up a very similar site. I just don't need the competition!

        If you are afraid someone is going to steal your ideas, get over it. If it was worth something you would either patent it or not share it.
        This program does not use a unique idea, therefore a patent wouldn't be granted. Nor could I afford the fees. That is a completely unplausible option for this.

        And yes, C is going to need many more lines of code because C does not handle text processing very well. This doesn't make it a bad language. I'm all for knowing several languages.
        I don't really mind how many lines of code the C is. It's likely to be longer than normal anyway as it's machine-generated. The fact is that it is not even compiling. The reason why I don't want to re-write the script in C or anything like that is because I find C programming extremely tedious, and I already have a brilliant working version of the program in Perl.

        Thanks for your suggestion about embedding the interpreter. Any more technical details on how to do this?

Re: Compiling Perl?
by turnstep (Parson) on Apr 29, 2000 at 01:06 UTC

    This has been discussed before (link anyone?) but if you don't want to put it into C, all you can do is obfuscate the code. Remove newlines, add random spaces, give variables really odd names, etc. You could also "cripple" it a bit - in other words, don't write the best code that you can, but leave in some errors and inefficiencies. Be redundant. The bottom line is that your code can be read, you just have to decide how much trouble you want to make it to do so.

      I remember the link. I think it was Protecting Perl Code. It was a slightly different issue -- this monk is concerned about a particular thievery-prone person, as opposed to the earlier monk who seemed to just be generally paranoid.

      I'm curious why SuperCruncher wants the other person to have a copy of the application at all -- is a face-to-face demo impossible or impractical?

      Stealing code against the author's wishes is SO gauche.

      Frankly, I'm not sure of what the best solution is. If the script is really big, I guess you'll have to compile it -- other people have actual technical suggestions on how to do this. Personally, I think it would be rather fun to go through the code and make it mostly-workable but wrong and bad and inefficient. Use . instead of join, s instead of tr, arrays instead of hashes. Put everything in one big object. Lowercase your filehandles and capitalize your subroutines. Indenting is a sign of brain fever. Use local when you mean my. (I could get carried away with this...)

      e-mail neshura

        I'm curious why SuperCruncher wants the other person to have a copy of the application at all -- is a face-to-face demo impossible or impractical?
        He wants a copy of the program. Fine. No problem. But I don't want to give him the code, because with a little bit of modification, he could easily remove the "dumbed down"-ness and use it in competition with me. I just want him to use this for his own personal use.

        Stealing code against the author's wishes is SO gauche.
        Put people do it! And I don't want this code to be stolen!

      This has been discussed before (link anyone?)
      I read previous discussions and Q&As at this site before I posted. Some of the Q&As were just verbatim copies of the standard perlfaq man pages!

      I appreciate your suggestion, but I'd hoped there was a better solution. I'll keep it as a last resort though.

      I have no problem with compiling into C, when I said I didn't like it, I meant for coding. If the code produced by perlcc compiled by me just typing:

      gcc -I /include/path/ -o mybinary.exe

      then I'd be very happy. But I get compiler errors. Perlcc does not even appear to be writing syntactically valid code!

RE: Compiling Perl?
by cciulla (Friar) on Apr 29, 2000 at 02:52 UTC
Re: Compiling Perl?
by ok (Beadle) on Apr 29, 2000 at 05:21 UTC
    So I know this isn't an answer to the original question, but to those who wonder what the poster's motives are, what's it to you? Just be a good monk and answer the question if you know a solution. Productivity is a lot more useful than philosophical debates.

    Kinda reminds me of the RTFM types who have enough time to write a long disparaging message to the asker but not enough precious time to say "type X and hit Enter."

    As for an answer, I agree with those who say "screw up the code." Perhaps one could write a little script to fudge up a perl program file...s/meaningful_var_name/xcE45Fkj/, rm_newlines(), et cetera.

Re: Compiling Perl?
by httptech (Chaplain) on Apr 29, 2000 at 19:15 UTC
    I'm curious as to why perl2exe won't compile the LWP or URI modules for you. I just compiled an LWP app with perl2exe a few minutes ago and it worked just fine. Perhaps there is something wrong with your installation?
      Sorry, it compiles fine. When I run it, it mysteriously fails - either with the LWP module or the URI module.
        Very strange. I haven't had any problems running my LWP app though. Possibly a bug in perl2exe. If it continues to be a problem when you compile other apps I'd recommend switching to another version of Win32 Perl (thus requiring a different build of perl2exe). That might fix it.

        Personally I'm running ActiveState Perl 5.005_03 build 522 and perl2exe V3.12b-AP5xx

RE: Compiling Perl?
by Anonymous Monk on Apr 30, 2000 at 20:49 UTC
    From the perlrun manpage:


      causes Perl to dump core after compiling your script. You can then in theory take this core dump and turn it into an executable file by using the undump program (not supplied). This speeds startup at the expense of some disk space (which you can minimize by stripping the executable). (Still, a ``hello world'' executable comes out to about 200K on my machine.) If you want to execute a portion of your script before dumping, use the dump() operator instead. Note: availability of undump is platform specific and may not be available for a specific port of Perl. It has been superseded by the new perl-to-C compiler, which is more portable, even though it's still only considered beta.

    This is probably useles on windows, but: where can I get this "undump" program? I can't find it on my debian machine..

Re: Compiling Perl?
by mcwee (Pilgrim) on Apr 29, 2000 at 18:49 UTC
    On a legally helpful (rather than technically helpful) note:

    In the US, you automatically have an explicit, exclusive copyright on any written work as soon as you pen it. Your Perl code is protected under the same laws which protect poets and novelists. As such, it should only be neccessary to make sure that your "pal" is very aware of this (i.e. "Hey, pal, before I mail this to you, please reply indicating that you are fully aware that this code is protected under US Copyright and I in no way grant you any rights to use, reprint, reproduce or make publicly availible this written work. Thanks, mom loves you, AM")

    Of course in this case you'll still run the risk of him or her being inspired by your work (the risk all authors run everytime they publish), but you do have quit a bit of legal recourse in the case that your code is plagarized wholesale.

    (Yeah, I know this isn't very helpful, but I think it's neat that code is considered written speech and so falls under the same legal jurisdiction. Another way in which Perl is poetry.)

    The Autonomic Pilot

RE: Compiling Perl?
by Anonymous Monk on Apr 29, 2000 at 06:56 UTC
    Re. the issue of the code being "stolen": under current law, your code is intellectual property. (Whether I personally agree with IP law - which I don't - isn't relevant here.) So, if you can't be assured that he won't "steal" your program, you have the option to license it to him under very strict and specific terms - "You are only allowed to USE the program, nothing more" and then sue him for copyright violation if he does anything else with it. If possible, get him to sign a contract making this explicit. (If you're in the US, you're in luck: under the DMCA, if you have any reason at all to suspect that he's breaching the license, one call to the feds and his computer gets seized. Yes, it's "censor first, ask questions later", and I don't like it one bit. But it definitely solves your problem.)
      I know that pretty much everything you write is copyrighted. Not just in the US - but any country that agrees to the Berne Convention.

      However there is no way I have the time or money to sue someone for something like this. There's simply no way I could do it.

      Hence my idea of just getting the code compiled, it solves the problem of the Joe Perl Public with a bit of Perl knowledge from hijacking code. Sure, it doesn't prevent the experts from reverse engineering it -- but hey, I can life with that.

Re: Compiling Perl?
by Anonymous Monk on Apr 29, 2000 at 18:02 UTC
    There this Perl Module that would encrypt/decrypt your source code. I think its called "Filter" or something.
RE: Compiling Perl?
by guaguanco (Acolyte) on Apr 29, 2000 at 00:55 UTC
    Why don't you want him to have the source?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://9628]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-10-28 12:31 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (96 votes). Check out past polls.