Re: Execute a Perl code without ".pl" extension
by jZed (Prior) on Mar 10, 2006 at 01:25 UTC
|
In order to answer your question, we'd have to know what shell and OS you are using. If you are using bash or a related *nix shell, then the "shebang" line of your code (the first line of the myperlcode script) should have a full path to your perl interpreter and the myperlcode file should be executable. If you're on some other OS or some other shell, that may not be sufficient. | [reply] |
Re: Execute a Perl code without ".pl" extension
by moklevat (Priest) on Mar 10, 2006 at 01:26 UTC
|
Assuming you are working on *nix:
1) You include the shebang #!/usr/bin/perl -w at the top of your script
Update:As Moriarty points out below, your shebang should point to your perl binary, which may be /usr/bin/perl, or may be /usr/local/bin/perl, or may be somewhere else, but can be found with the command which perl
2) Rename your script from myperlcode.pl to myperlcode
3) Change permissions on your script like: chmod +x myperlcode | [reply] [d/l] [select] |
|
This isn't completely true
1) This will only work if the perl executable is in /usr/bin/ (which just happens to be the most popular place to put it).
2) It is not necessary to rename the script as *nix doesn't care about extensions.
| [reply] |
|
| [reply] [d/l] |
|
|
Re: Execute a Perl code without ".pl" extension
by holli (Abbot) on Mar 10, 2006 at 20:33 UTC
|
For Windows you'll need to add ";.pl" to the PATHEXT environment variable. (given that the .pl extension is associated with the perl executable, which is always the case with a normal Active Perl installation.)
| [reply] |
|
Thanks holli, for that information!
When I saw the title of this node, my first thought was that it would answer a question I, too, have been having, ever since installing Perl on this new laptop. It seemed natural to assume the question was related to running on Windows ... but I had to read down to the last of the messages before I found the only one which applied to my situation ... yours. Danke sehr ;)
@ARGV=split//,"/:L";
map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
| [reply] |
Re: Execute a Perl code without ".pl" extension
by izut (Chaplain) on Mar 10, 2006 at 10:25 UTC
|
#!/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.
| [reply] [d/l] [select] |
|
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.
| [reply] |
|
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.
| [reply] [d/l] |
|
|
|
|
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. | [reply] [d/l] |