Dan.Pinvidic has asked for the wisdom of the Perl Monks concerning the following question:

Our current method to run perl, is a wrapper script which determines what machine you are on, and finaly calls the correct PERL executable. The script begins with #!/usr/bin/sh. Now my personal perl script begins with: #!/usr/bin/env /bin/perl_wrapper -w this problem is a Unix problem where the -w is interpreted as a file name, and I get a -w file not found error. If I remove the -w, the nested scripts work fine. Is there another method to have the first line of my personal PERL script call a wrapper (for binary selection) and still pass perl options. Or a bteer way to select the right binary? Users may want specific perl versions. Thanks, Dan

#!/usr/bin/env perl_wrap -w #Above line fails with -w not found #!/usr/bin/env perl_wrap #Above line works fine

Replies are listed 'Best First'.
Re: How can I control perl binaries
by frozenwithjoy (Priest) on Jun 23, 2012 at 00:38 UTC
    "Or a better way to select the right binary? Users may want specific perl versions."

    My favorite way to allow easy switching between perl versions is with Perlbrew.

Re: How can I control perl binaries
by 2teez (Vicar) on Jun 23, 2012 at 01:03 UTC

    "..this problem is a Unix problem where the -w is interpreted as a file name, and I get a -w file not found error..."
    Instead of using the -w pragma why not just use use warnings in your programs.

      There are other options (like -e) that I would like to use with this.

        You can't use or emulate -e on #! line, can you?

Re: How can I control perl binaries
by Anonymous Monk on Jun 23, 2012 at 07:30 UTC
    Edit ~/.bashrc and append /your/favorite/perl/path to $PATH , none of this wrapper shell scripting nonsense

      Even better, prepend the path to your favorite perl to $PATH, so it will be found before any others in your path.

      sh$ PATH=/bin:/usr/bin:/home/me/bin sh$ which perl /usr/bin/perl sh$ PATH=/home/me/bin:/bin:/usr/bin sh$ which perl /home/me/bin/perl

      Aaron B.
      Available for small or large Perl jobs; see my home node.

        Good point on using -e in a #! line. Guess I got hung up on that. This wrapper script is put inplace by our IT department so the correct binary will be run based on the users machine. And after getting input from this group, I think we are OK. the -w can be put into the actual perl script with "use strict". All of the other "real" command line options seem to pass thru the wrapper correctly when they are actually present on a command line from STD_IN. So I did learn a little more of how the #! line works. Thanks for the feedback. Dan