Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: #!$var/bin/perl

by LAI (Hermit)
on Mar 13, 2003 at 16:39 UTC ( #242743=note: print w/replies, xml ) Need Help??

in reply to #!$var/bin/perl

Like hardburn said, the shebang line is interpreted by the system, not Perl. So, if you want to make sure all your systems have the right path set, I would suggest that you have a simple installation script that you run whenever you upload code. Recurse through your root code directory and replace any perl shebangs you find with the right one.

use strict; # duh. use File::Find; find ( sub { open IN, "< $_" || return; # silently discard failed o +pen chomp(my $firstline = <IN>); # read in first line and $firstline =~ /^#!.*perl[\s\Z]/ && do { # check for a shebang $firstline = "#!$^X$'"; # replace with your own she +bang chomp(my @nextlines = <IN>); open OUT, "> $_" && do { # print the file back out map {print OUT $_,$/;} $firstline, @nextlines; close OUT; } # the next bit is a little more concise, but won't replace newli +nes #$firstline = "#!$^X$'$/"; #my @nextlines = <IN>; #open OUT, "> $_" && do { # map {print OUT} $firstline, @nextlines; # close OUT; #} close IN; }, qw| /source/code/directory /another/source/dir |; )

If you call this as perl the special variable $^X will insert the name of your perl executable as 'perl', so run it using /var/binaries/coolest/perl or wherever your executable happens to be.

Note: This was written off-the-cuff, and thoroughly untested. Use this only as a guideline and test it thoroughly before actually using it on any production code. Seriously.

Update: you probably want to write a little shell script on each system, something to the effect of

#!/bin/bash /var/binaries/coolest/perl /usr/local/bin/

That'll simplify your life a little.

Update: as I was cleaning the code a little I realized that this might actually have the happy effect of replacing the newlines in your perl files with your system's $/. I may be wrong, tho.



Replies are listed 'Best First'.
Re: Re: #!$var/bin/perl
by IlyaM (Parson) on Mar 13, 2003 at 17:31 UTC

      IlyaM++ you're right, of course. I remember the documentation to ExtUtils::MakeMaker being huge, though, and assuming changing the shebang line is all that needs to be done for the install (yeah, right), I'd probably prefer to write a small script like this one rather than pull in a module and use that.

      Of course, having said that, I do know that there are issues with my own snippet, and that everything it does is done better by MakeMaker, but false laziness and an eye toward getting this over with and getting back to work tell me that repackaging and redeploying stuff for every update (as well as installing MakeMaker on all the target boxen) is more work.

      Update: to continue with my habit of pointing out my own fallacies, I would note that the fact that I spend a nontrivial amount of time reading and commenting on PM nodes, as well as chatterboxing or just following interesting CB conversations, should prompt me to keep my mouth shut about "getting this over with and getting back to work"...



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://242743]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-05-26 03:15 GMT
Find Nodes?
    Voting Booth?