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

Hi,
Suppose I have a code (mycode.pl) that has include the following modules
#!/usr/bin/perl -w use strict; use Algorithm::Loops 'NestedLoops'; use List::Compare; use List::Util qw (min max); use somelib; # (somelib.pm) # rest of the code
Now I want to 'compile' into an 'executable' of this code using PAR's pp utility. I tried the following command:
#!/usr/bin/bash pp -M Algorithm::Loops qw(NestedLoops) -M List::Compare -M List::Util +qw(min max) -a somelib.pm mycode.out
But it gives:
-bash: syntax error near unexpected token `('
What's the way to overcome this?

Regards,
Edward

Replies are listed 'Best First'.
Re: Howto include Module with Specific Methods with PAR's pp utility
by McDarren (Abbot) on Oct 28, 2006 at 02:05 UTC
    Monkfan,

    As discussed privately, you don't need to include all those module calls on the command line. Whatever is included (use'd) in your script will be included in the executable.

    All you really need is something like:

    pp -o mycode.exe mycode.pl

    Cheers,
    Darren :)

      McDarren, Thanks for the pointer.

      But if it is automatically done, then on what circumstances
      -M option should/can be used, as described in pp doc?

      Regards,
      Edward
        what circumstances -M option should/can be used

        Sometimes pp fails to pull in a module if the script does not explicitly use that module. Not sure of the details, but it can happen - and if that does happen, then you can use the -M option to load the module. So ... I guess you're wondering what to do when when the module that pp fails to pull in needs to also export some functions.

        I don't think pp's -M switch can handle that - though I could be wrong. I certainly didn't manage to find an incantation that works.

        You can, however, work around the problem by rewriting the perl script so that it explicitly loads the module and exports the desired functions. That way there will be no need to load the module using the -M switch.

        Cheers,
        Rob
Re: Howto include Module with Specific Methods with PAR's pp utility
by Joost (Canon) on Oct 28, 2006 at 11:28 UTC