Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Conditionally executing different versions of Perl

by blokhead (Monsignor)
on Oct 18, 2006 at 21:46 UTC ( [id://579214]=note: print w/replies, xml ) Need Help??


in reply to Conditionally executing different versions of Perl

To the best of my knowledge, you cannot have two levels of shebang-activated programs. So if you run ./test.pl which starts with #!/some/program, then /some/program cannot also be a shebang program.

The solution (or at least a solution) is to call /usr/bin/env, which itself does shebang-emulation, instead of calling your wrapper directly.

/path/to/perlwrapper:

#!/usr/bin/perl print "wrapper about to execute @ARGV\n"; exec "/usr/bin/perl", @ARGV;
test.pl:
#!/usr/bin/env /path/to/perlwrapper print "hello world!\n";
And then executing ./test.pl should work (at least, it did for me). Changing all your scripts to use env in their shebang line is a pain (you cannot just repace /usr/bin/perl with your wrapper), but it's the only way you can emulate nested shebangs. Otherwise, you'd have to make this version-delegation wrapper into a compiled binary.

There are also further complications: It appears that if the shebang line doesn't contain the word "perl", then perl itself will try to emulate shebangs and start an infinite loop (re-invoking your version-delegation wrapper). So I got weird results when I first named it "wrapper" instead of "perlwrapper"...

blokhead

Replies are listed 'Best First'.
Re^2: Conditionally executing different versions of Perl
by MidLifeXis (Monsignor) on Oct 19, 2006 at 17:28 UTC

    ++

    You learn something new every day. Have to file this away in my bag-o-tricks.

    --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://579214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-26 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found