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

Hello,

I've started learning 'pp' ( http://search.cpan.org/~smueller/PAR-Packer/lib/pp.pm ).

I think I understand how it works in general, and in practice I can create a stand-alone executable from a simple script.

So far so good.

I know that in reality I'll need to create stand-alone executable from a number of Perl scripts, so let's simplify this yo just father.pl calling son.pl .

Normally I would call son.pl (there are no command line arguments to it for simplicity):

system("$^X -w son.pl"); # it is assumed son.pl is in CWD
.

So, with 'pp' I have a problem WRT $^X.

This is my father script:

#!/home/sergei/PERL-5.10.0/bin/perl -w use strict; warn "this is father, \$0=$0 \$^X=$^X"; warn "father.pl: \@INC=\n", join("\n", @INC); warn "cwd: ", `pwd`; warn "PATH: ", `echo \$PATH`; my @PATH = split(':', $ENV{PATH}); warn "\$PATH[0]=$PATH[0]"; warn "father.pl: \$^X=$^X"; { warn "father.pl: about to check Perl (\$^X)"; my $cmd = "$^X -h"; warn "\$cmd=$cmd"; system($cmd); warn "father.pl: \$?=$?"; }
. When run from command line directly it works as expected:
" ./father.pl this is father, $0=./father.pl $^X=/home/sergei/PERL-5.10.0/bin/perl a +t ./father.pl line 7. father.pl: @INC= /home/sergei/PERL-5.10.0/lib/perl5/5.10.0/i686-linux-thread-multi /home/sergei/PERL-5.10.0/lib/perl5/5.10.0 /home/sergei/PERL-5.10.0/lib/perl5/site_perl/5.10.0/i686-linux-thread- +multi /home/sergei/PERL-5.10.0/lib/perl5/site_perl/5.10.0 . at ./father.pl line 8. cwd: /home/sergei/junk/perl_package PATH: /opt/kde3/bin:/home/sergei/bin:/usr/local/bin:/usr/bin:/bin:/usr +/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/jvm/jre/bin:/usr/lib/mit/ +bin:/usr/lib/mit/sbin $PATH[0]=/opt/kde3/bin at ./father.pl line 14. father.pl: $^X=/home/sergei/PERL-5.10.0/bin/perl at ./father.pl line 1 +6. father.pl: about to check Perl ($^X) at ./father.pl line 19. $cmd=/home/sergei/PERL-5.10.0/bin/perl -h at ./father.pl line 21. Usage: /home/sergei/PERL-5.10.0/bin/perl [switches] [--] [programfile] + [arguments] -0[octal] specify record separator (\0, if no argument) -a autosplit mode with -n or -p (splits $_ into @F) -C[number/list] enables the listed Unicode features -c check syntax only (runs BEGIN and CHECK blocks) -d[:debugger] run program under debugger -D[number/list] set debugging flags (argument is a bit mask or alp +habets) -e program one line of program (several -e's allowed, omit pr +ogramfile) -E program like -e, but enables all optional features -f don't do $sitelib/sitecustomize.pl at startup -F/pattern/ split() pattern for -a switch (//'s are optional) -i[extension] edit <> files in place (makes backup if extension +supplied) -Idirectory specify @INC/#include directory (several -I's allo +wed) -l[octal] enable line ending processing, specifies line term +inator -[mM][-]module execute "use/no module..." before executing progra +m -n assume "while (<>) { ... }" loop around program -p assume loop like -n but print line also, like sed -P run program through C preprocessor before compilat +ion -s enable rudimentary parsing for switches after prog +ramfile -S look for programfile using PATH environment variab +le -t enable tainting warnings -T enable tainting checks -u dump core after parsing program -U allow unsafe operations -v print version, subversion (includes VERY IMPORTANT + perl info) -V[:variable] print configuration summary (or a single Config.pm + variable) -w enable many useful warnings (RECOMMENDED) -W enable all warnings -x[directory] strip off text before #!perl line and perhaps cd t +o directory -X disable all warnings father.pl: $?=0 at ./father.pl line 23. ".
However, when run as packaged stand-alone script, it fails:
" (export PATH=/opt/kde3/bin:/home/sergei/bin:/usr/local/bin:/bin:/usr/X +11R6/bin:/usr/games:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mi +t/sbin;./father) this is father, $0=./father $^X=perl at script/father.pl line 7. father.pl: @INC= /tmp/par-sergei/cache-e0cd5bf94ffa04802f4f5c756f59f68f58993e95/inc/lib /tmp/par-sergei/cache-e0cd5bf94ffa04802f4f5c756f59f68f58993e95/inc CODE(0x8736488) CODE(0x87367d8) at script/father.pl line 8. cwd: /home/sergei/junk/perl_package PATH: /tmp/par-sergei/cache-e0cd5bf94ffa04802f4f5c756f59f68f58993e95:/ +opt/kde3/bin:/home/sergei/bin:/usr/local/bin:/bin:/usr/X11R6/bin:/usr +/games:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin $PATH[0]=/tmp/par-sergei/cache-e0cd5bf94ffa04802f4f5c756f59f68f58993e9 +5 at script/father.pl line 14. father.pl: $^X=perl at script/father.pl line 16. father.pl: about to check Perl ($^X) at script/father.pl line 19. $cmd=perl -h at script/father.pl line 21. father.pl: $?=-1 at script/father.pl line 23. "

- I intentionally modified $PATH _not_ to include paths to system-wide Perl.

So, where is Perl interpreter in the stand-alone executable ? Is it possible to use it to run child scripts ? Thanks, Sergei.

Replies are listed 'Best First'.
Re: pp - where is the Perl interpreter ?
by mr_mischief (Monsignor) on May 14, 2009 at 19:00 UTC
    Using parl requires a core perl on the system. Using pp packages that along with each application, so that no perl needs to be installed on the target. It is extracted from the archive and run with the program you wrote handed to it as input, basically.

      I thought about wrapping the sons as pp packages, but it looks silly - the difference between fathers and sons is their bytecode, so why to replicate the whole thing, including the interpreter ?

      I understand that an interpreter instance has to be invoked per father/son, but why to replicate all the binary files belonging to interpreter ?

        That's simply the way the tool works. There's actually a decent argument if you're going to be packaging multiple programs as part of one application (or application suite/group) not to use pp to do so, to avoid that replication.

        It may take some more fiddling and be less convenient for you as the developer, but since any recent perl should be relocatable on disk you can actually provide one single perl in your project's installation directory. You can then have all the programs use that. You can then package with parl rather than pp or not package the programs up at all. You'd just have your installation program extract the whole thing and set up any shortcuts or menu items.