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

I'm still a little new to Perl on a win32 system, and I was wondering which of these shebang lines is the correct one to use in my code?
If my code was to ever run on another type of O.S. I'd probably go with B) but since I'm only using Windoze 2000, I want to lean more towards C)
Thanks!
# A) #!perl # B) #!/usr/bin/perl use strict; use warnings; use win32; # C) #!perl use strict; use warnings; use win32; # D) #!/usr/bin/perl-w use strict;

Replies are listed 'Best First'.
Re: win32 shebang
by earthboundmisfit (Chaplain) on Aug 08, 2001 at 19:11 UTC
    Win32 ignores everything in the shebang EXCEPT the switch (-wt, etc.). So 'D' is the only one that will have any effect.

    You could just as easily do:
    #!/theworld/is/my/oysterPerl -w
    update: fixed my statement after Hofmator reminded me that the word Perl has to be in there

Re: win32 shebang
by Hofmator (Curate) on Aug 08, 2001 at 19:24 UTC

    First of all, the shebang line is only the line beginning with '#!'. You remarked correctly that on Windows this has no meaning to the OS but perl will always look into that line and extract command line parameters if it contains the word perl. From this point of view it doesn't matter if you write #!perl or #!/usr/bin/perl or #!ohmegod, it's perl. On *nix this line specifies the location of the perl executable which is normally (but not always) located in /usr/bin.

    Concerning the use statements, I would go for

    use 5.6.0; use strict; use warnings;
    as was recently discussed here. The discussion there also explains the difference between perl -w and use warnings; Your use win32; includes the win32 which provides specific functions for Windows (surprise :) but you only use it if you need some of these functions.

    -- Hofmator

      Um, please don't do "use 5.6.0;" as that doesn't work quite right in versions of Perl prior to v5.6. Do "use 5.006;" instead.

              - tye (but my friends call me "Tye")
        So what does it do?

        My guess is that it will parse it as the float 5.6 and ignore the rest. That will be compared against the internal 5.005 and it will tell you (correctly) that it's not good enough.

Re: win32 shebang
by tachyon (Chancellor) on Aug 08, 2001 at 19:21 UTC
Re: win32 shebang
by mexnix (Pilgrim) on Aug 08, 2001 at 23:17 UTC
    Also, if you ever decide to do CGI stuff with apache on Win32 (don't we all?), the shebang has to be

    #!perl -w
    use strict;

    So basically (D), with no path info. This is very important because they'll run on the command line all day with

    #!/usr/bin/perl -w
    use strict;

    but not from the web.

    Just my 2 cents worth.

    __________________________________________________
    <moviequote name="Hackers">
    The Plague: [...]Well let me explain the New World Order. Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo!
    </moviequote>

    mexnix.perlmonk.org

Re: win32 shebang
by Kiko (Scribe) on Aug 08, 2001 at 20:02 UTC
    I always like to use:
    #!/perl/bin/perl -w use strict; use Win32::ODBC; #for Access or MsSql Server use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser);
      THANKS! Updating all of my code!
Re: win32 shebang
by John M. Dlugosz (Monsignor) on Aug 09, 2001 at 03:06 UTC
    With the advent of use warnings; I never use a shebang line at all anymore, for Win32 programming.

    I associate the file extension ".perl" with the full path to the perl interpreter, and so-name the main executable file.

    —John