targetsmart has asked for the wisdom of the Perl Monks concerning the following question:

I am using activeperl 5.6.1 on MSWin32
I was using perl scripts on *nix systems with shebang so far, now I am writing Perl scripts on windows, accidentally i forgot to put shebang line inside the perl script, and i executed the script 'script.pl' it executed fine. It didn't complained. how is it like this in windows? In *nix it would have surely complained without shebang.

IMO it has identified by .pl file extension, because when i change the file extension to something like .ppl, it asks me to choose the appropriate program for opening the file, it doesn't execute automatically.


Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Replies are listed 'Best First'.
Re: .pl or shebang
by cdarke (Prior) on May 15, 2009 at 08:05 UTC
    A few other notes. On Windows it is up to the shell, or application running the program, to get the file extension association from the registry - the OS does not do it (see Win32::FetchCommand).
    You can get a list of file extension associations on the command-line with:
    assoc|more
    You should see: .pl=Perl. Perl is associated with the perl executable in the registry as well (HKEY_CLASSES_ROOT)
    You can create a new association on the command-line with (for example):
    assoc .ppl=Perl
    The effect is saved in the registry.

      Maybe it's worth also mentioning the other one, which associates file types with the actual commands: ftype

      The OS does do it. Depends on the function you call. See Win32::FileOp::ShellExecute.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Re: .pl or shebang
by grizzley (Chaplain) on May 15, 2009 at 06:27 UTC
    Yes, it works exactly as you think: the shebang line is ignored on windows, and script is identified by extension .pl, which is stored in registry and associated to perl executable.
      the shebang line is ignored on windows

      Not ignored *completely*. Switches such as '-l', '-w', and '-T', are honoured - and, last time I checked, the shebang line (if present) had to match the string 'perl'.

      Cheers,
      Rob
        yup
        C:\>perl #!/usr/bin/PYTHON -T -- Can't exec /usr/bin/PYTHON at - line 1. C:\>
        "-T" in the file will not work. You have to change the executable path in the registry and add it or call it from the cmdline: "perl -T foo.pl"
Re: .pl or shebang
by wol (Hermit) on May 15, 2009 at 10:26 UTC
    I am using activeperl 5.6.1 on MSWin32
    You have my sympathy - I too am labouring under this restriction. :-(

    --
    use JAPH;
    print JAPH::asString();

Re: .pl or shebang (.bat)
by tye (Sage) on May 16, 2009 at 06:28 UTC

    I don't think you should have to know what language a tool is implemented in just to use the tool. So I don't like to launch perl scripts via "perl script ..." nor "script.pl ...". On Windows, I prefer to use pl2bat which turns your Perl script into a *.bat file that can be run without jumping through configuration hoops.

    - tye        

        I use pl2bat too. Can't say I like it though. :) I use it for the reason mentioned by tye and because I need pipelines and file redirection to work, and last time I looked these two were badly broken by file associations, as documented at Perl 5.8.9 pl2bat doco (see the "ADVANTAGES" section).

      I would not call associating .pl with perl.exe and adding .pl into PATHEXT "hoops". I would not want to jump through the pl2bat hoop every time I create a script or update the not-mangled instance of the script. Especially since the Perl installation (at least ActiveState, but I bet others as well) does at least the association.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.