in reply to Execute a Perl code without ".pl" extension

I always put the following

#!/usr/bin/env perl

instead other common shebang (#!) lines. It will call env(1) and then execute perl from environment (looking in /bin, /usr/bin, etc.).

Update: As Anonymous Monk said, the correct canonical path is /usr/bin/env.

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^2: Execute a Perl code without ".pl" extension
by wazoox (Prior) on Mar 10, 2006 at 11:24 UTC
    Be careful, it may bite you in production environment because the environment of a user isn't garanteed, and many systems have several perl executables installed... Especially, don't do that on a web environment, it may be a huge security risk.

      I work basically with Red Hat environments, just one Perl installed. I can't see the point using that in a web environment. Did you mean CGI or mod_perl? If it is mod_perl, does it cares as Apache uses the embedded interpreter? And about the CGI case, I think env will load the environment of user that is supposed to run the web server, or am I wrong?

      Igor 'izut' Sutton
      your code, your rules.

        It shouldn't be a problem with mod_perl actually, but in CGI mode it uses the apache environment; you can't really be sure that there isn't an executable somewhere called "perl" that isn't what you expect it to be...

        Here's the Apache $PATH on my RHEL 4 system : /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

        And here's the path for some regular user : /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/bin

        Someone for some reason, may have installed for instance a setuid perl as /usr/sbin/perl, which isn't in the user's path, but would be run FIRST by Apache... And here's your CGI running as root, howdy!

        Well, I hope you've got my point : using #!/bin/env perl for your own personal scripts is OK, but please don't do that for production code.

Re^2: Execute a Perl code without ".pl" extension
by Anonymous Monk on Mar 10, 2006 at 19:14 UTC
    sorry to disappoint you, but the canonical path to env is /usr/bin so please write
    #!/usr/bin/env perl
    And yes, that should work on any *nix system, according to somme standard which name I conveniently forgot (so you can't check me on this ;-), but (seriously!) remember to have read about.