Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: different exe path for different OS

by bergbrains (Acolyte)
on Aug 31, 2010 at 20:59 UTC ( [id://858231] : note . print w/replies, xml ) Need Help??


in reply to Re^3: different exe path for different OS
in thread different exe path for different OS

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.