• Comment on Turn your script into binary without a compiler! :-P

Replies are listed 'Best First'.
Re: Turn your script into binary without a compiler! :-P
by Courage (Parson) on Jul 24, 2002 at 11:15 UTC
    I like your idea. Here are my comments.

    I think recompiling a perl is overkill in your case. I had similar solution, and I suggest you can get a couple ideas from my node: perl scripts executor on Win32

    I think if we'll mix both ideas, we could get much simplier and flexible solution.

    Now improvements that I want to suggest to your idea and code.

    • No need to recalculate size and edit executable to find and replace substring in there. Do it better: append special magic string after your executable, and a script immediately after that. perlbin.pl will search for that string and, if not found, append magic string and script. If found, just replaces script.
    • I don't think you need my @ARGS = @ARGV. Just work directly with @ARGV.
    • just do something like
      open F,"<$^X"; binmode F; my $x = join '',<F>; $x=~s/^.*magicstring//s; eval $x
    • $^O=~/(msw|win|dos)/ is in trouble: Darwin will match it but that's no good. Check it for just 'MSWin32'

    Courage, the Cowardly Dog.

      I made in this way, with string to change inside the 
      binary, because if this string are not changed, starting 
      with #, the binary will work like the normal perl.exe
      
      Since this is made for HWXperl, when I delivery hwxperl I 
      can get any binary of the release and turn into a script! I 
      made this with miniperl.exe too, where you don't need the 
      perllib in the same directory.
      
      I don't understand what you means with 
      "I don't think you need my @ARGS = @ARGV. Just work 
      directly with @ARGV". Are you talking about the 'char argv' 
      on the C code? If is about this, I just made in the most 
      simple and portable way, because some compilers don't deal 
      with argv equally.
      
      about '$^O=~/(msw|win|dos)/', yes is not very pretty, but 
      here, when the binary can't find it self, I will put all 
      the options to fix this in any OS, here are only for Win32.
      I saw one time a vendor with 'MSwin' in the $^O, but I 
      think this is too old. Seeing again the table, I will 
      change this line...
      
          OS            $^O        $Config{'archname'}
          --------------------------------------------
          MS-DOS        dos
          PC-DOS        dos
          OS/2          os2
          Windows 95    MSWin32    MSWin32-x86
          Windows 98    MSWin32    MSWin32-x86
          Windows NT    MSWin32    MSWin32-x86
          Windows NT    MSWin32    MSWin32-ALPHA
          Windows NT    MSWin32    MSWin32-ppc
      
      I will see your code on 'perl scripts executor on Win32'. 
      Thanks for the link, and the reply...
      
      "The creativity is the expression of the liberty".
      
Does exactly what it says on the tin... Re: Turn your script into binary without a compiler! :-P
by osfameron (Hermit) on Jul 24, 2002 at 07:54 UTC
    Nice idea! But
    After this compile Perl (make|dmake)
    I guess that working out how to compile Perl without a compiler was left as an exercise to the reader? ;->

    Cheerio!
    Osfameron
    http://osfameron.perlmonk.org/chickenman/