You're correct, Salva. If you exec before you exit the BEGIN block, you're safe from the problems I noted regarding missing modules.

#!/usr/bin/perl BEGIN {exec ("echo", "Blast it, Jim! I'm a doctor, not a magician!");} use Some::Bogus::Mod;

...does not throw the "Can't locate..." exception, whereas if you get beyond the BEGIN block, the use line will barf.

So, we now have two viable options:

  1. There's Moritz's solution in which you replace your bang line with '#!/usr/bin/env perl' and make sure your PATH has the correct directory prepended to it; and
  2. And Salva's recommended method, based on a hash of paths to platform-specific Perl binaries.

I looked at using $^O to get the key to identify the right Perl for the platform, but I've got two Linux installs -- one for 32-bit and one for 64-bit, and $^O only shows 'Linux'. I took a quick look at this: http://search.cpan.org/perldoc?perlport#PLATFORMS. There's probably something available in the Config module that would provide the granularity I'm looking for.

I want to make sure that I'm able to derive the path to my executables from both Perl and shell scripts -- I'm now using `uname -p`.

Thank you both for these solutions. Currently, our processes run in multiple environments (mainly DEV, STAGE and PROD), and we source a profile for each to pick up a number of variables that dictate various behaviors including directories and to which db we connect. I think we're going to go with Mortiz's env-on-the-bang-line solution, because it fits in better with our existing process.


In reply to Re^4: different exe path for different OS by bergbrains
in thread different exe path for different OS by bharatbsharma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.