#!/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:
- 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
- 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.
|