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

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

Replies are listed 'Best First'.
Re^2: Execute a Perl code without ".pl" extension
by Moriarty (Abbot) on Mar 10, 2006 at 01:45 UTC

    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.

      Fair enough, but even though *nix doesn't care what the file is named, the OP wanted to know how to do

      $ ./myperlcode param > someoutput.txt

      and the original script was named myperlcode.pl.

        My personal preference is to leave to ".pl" in place as it tells me that I can edit it as a normal Perl script.