tags:

views:

66

answers:

2

I have written a small script in Perl which I am executing on Windows with ActivePerl as below:

C:\Documents and Settings\Administrator> perl io.pl io.pl
#!/usr/bin/perl
use warnings;

sub test6 {
    while (defined($_ = <>)) {
        #chomp($_);
        print $_;
    }
}
test6;

As you can see, the code is similar to the Unix cat command:

C:\Documents and Settings\Administrator> perl io.pl io.pl

If I want to execute this script without the perl keyword on the command line, what needs to be done? I want the script to be executed as:

C:\Documents and Settings\Administrator> ./io.pl io.pl
+3  A: 

The .pl extension needs to be associated with the Perl interpreter, for one thing. This is easily done by trying to open the script from Windows Explorer -- when you're asked what program to use to open it, browse to perl.exe. And make sure the "always use this program..." box is checked.

Windows likes to check the current directory first, so you don't need to have the "./" in there.

cHao
If you feel like living dangerously take a look at the `PATHEXT` variable. It contains the semicolon separated list of extensions you can omit when executing a program in the windows cmd shell.`set PATHEXT=%PATHEXT%;.PL` will let you run `io.pl` as just `io`
Ven'Tatsu
A: 

i think specifying the perl install directory location at the start of the perl script should do it.

#!<perl install directory\bin\perl > rather then #!usr/bin/perl 
Anil Vishnoi
Windows doesn't read shebang lines. Cygwin might, but ActivePerl is usually run on Windows without Cygwin.
cHao