I have set up a local Perl web environment on my Windows machine. The application I'm working on is originally from a Linux server, and so the shebang for source .pl
files look like so:
#!/usr/bin/perl
This causes the following error on my Windows dev machine:
(OS 2)The system cannot find the file specified.
Is it possible to change my Apache 2 conf so that the shebang is ignored on my Windows machine? Of course I could set the shebang to #!c:\perl\bin\perl.exe
, that much is obvious; but the problem comes to deploying the updated files. Clearly it would be very inconvenient to change this back on each deploy. I am using ActivePerl on Windows 7.
Update:
I should have mentioned that I need to keep the shebang so that the scripts will work on our shared hosting Linux production server. If I did not have this constraint and I didn't have to use the shebang, the obvious answer would be to just not use it.
I don't have Windows handy, but perlcritic says:
So, I guess
#! perl
should work.Edit: doesn't work on linux; apparently works in
parrot
, although I don't see how they manage that.Create a trivial redirecting shell script:
Create a registry entry:
(...and so on.)
Jot in your
httpd.conf
file:Apache will now resolve Unix shebangs relative to the interpretation given by your choosen Bash flavor. This gives much more flexibility than hardcoding interpreter paths in the registry.
There is no portable shebang line. Even on the same platform and architecture, someone might have installed perl is a different location.
The trick is to not install modules and scripts by hand. When you package everything as distributions and use the module toolchain, the shebang lines are modified automatically to point to the perl you used to install everything. You shouldn't have to think about these details. :)
The way I had this working was to copy perl.exe to c:/usr/bin/ and rename it to perl (strip the .exe)
I use #
! /usr/bin/env perl
as the shebang on all of my perl, whether on *nix or Windows. Windows just ignores it, and the Unixen follow env to the chosen perl disto.I use
#!/usr/bin/perl
in my scripts and configure Apache on Windows to ignore the shebang line. Addto your
httpd.conf
and set up the Windows Registry key as explained in the Apache docs.Here is what I get when I export the key:
I have been using this setup with Apache and ActiveState Perl on my Windows laptop and the Apache and Perl distributions that come with ArchLinux on my server.
The Apache docs (to which I linked above) state: