Hold fire man - I am not asking how to do it, I am presenting a way it can be done.

Hiding the source code is not possible in perl - it can only be made less easy to read. However the following script can be used with interactive code to encrypt the functional bits.

#!/usr/local/bin/perl -w # An attempt at an end to those damn 'hide the source' nodes. # Usage: close-the-source.pl open_source.pl closed_source.pl # If you want to know what is going on go to: # http://perlmonks.com/index.pl?node_id=264840 use strict; use Crypt::Simple prompt => 'Please type the password now'; # Get the in and out off the command line. my $in_file = shift @ARGV; my $out_file = shift @ARGV; # Open the files. open IN, $in_file or die "Please specify file to scramble: $!"; open OUT, ">$out_file" or die "Please specify file to save to: $!"; # Grab the data and close the file. my @data = (); while (<IN>) { push @data, $_; } close IN; # Scramble the data my $scramble = encrypt( @data ); # Create closed_source.pl print OUT << "END"; #!/usr/local/bin/perl -w # If you want to know what is going on go to: # http://perlmonks.com/index.pl?node_id=264840 # Usage: 'perl $out_file | perl - args' use strict; use Crypt::Simple prompt => 'Please type the password now'; my \$scramble = '$scramble'; my \@clear = decrypt( \$scramble ); my \$code = join '', \@clear; print \$code; END # Be neat. close OUT; # Be rude. print "\n\nRight - run 'perl $out_file | perl - args' and stop pesteri +ng us.\n\n";

What it does is take the source code and encrypt it. Then it slaps the encrypted code into another perl script - whose only job is to decrypt the code and print it to STDOUT. This can be piped to perl and voila - hidden source execution of perl.

Take this test script as an example:

#!/usr/local/bin/perl -w print 'Look Dad - we can make millions now!', "\n\n"; print "Arguments are: ", join (', ',@ARGV), "\n\n";

Now run this at the prompt:

[evdb@machine]$ perl close-the-source.pl test.pl out.pl Please type the password now: secret Right - run 'perl out.pl | perl - args' and stop pestering us. [evdb@machine]$ perl out.pl | perl - 1 2 3 Please type the password now: secret Look Dad - we can make millions now! Arguments are: 1, 2, 3 [evdb@machine]$
It is not perfect but at least it should satisfy some of the requests for closing the source... Oh, and you should probably pick another encryption method if you are serious about this (and test it further - although it can handle html2ps just fine, and make the file smaller).

Update: Minor tweak to code (moved second #! line and added usage comment to closed source script).

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.