Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Using Perl, some Windows version and #!usr/bin/perl, WHY?

by muba (Priest)
on Mar 20, 2004 at 19:49 UTC ( #338352=perlquestion: print w/replies, xml ) Need Help??

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

As you can all see, I am quite new to PerlMonks.
While just hanging around over here, checking some code left and right, reading some nodes and comments, I have seen a strange thing: code written for some Windows version, having this -or something similar- as the first line:
#!usr/bin/perl
For goodness sake, why? What's the sense of a shebang when it points to a directory that can't exist on your system? What's the sense of a shebang if your shell does not support them?

Don't misunderstand me: I use shebangs myself too. They're for the CGI scripts I write to test things on/with my Win32 webserver (Xitami) and they look like: #!perl or #!d:\perl\bin\perl.exe so they do make sense.

But I just don't get in what other cases you would want to use a shebang. Oh yeah, maybe when you use cygwin. But then... why to /usr/bin/perl?

Replies are listed 'Best First'.
Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by TStanley (Canon) on Mar 20, 2004 at 20:44 UTC
    If I remember correctly, both Windows and Unix look on the shebang line for any switches passed in(i.e. the -w or -i switches)

    TStanley
    --------
    The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke
Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by etcshadow (Priest) on Mar 20, 2004 at 21:01 UTC
    Well, for one thing, the use of the shebang line is just habit. For another, the perl interpretter will honor command line switches following "perl" on the shebang line... regardless of what's between the shebang and the "perl".

    Mostly, though, as I said... I think it's just habit.

    ------------ :Wq Not an editor command: Wq
      Ok... that makes sense. Still it's strange and confusing to use /usr/bin/perl. Isn't there an theory in which it is said you should use the right thing for the right job? Doesn't that apply here?
Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by jZed (Prior) on Mar 21, 2004 at 01:02 UTC
    What's the sense of a shebang when it points to a directory that can't exist on your system?

    Why can't it exist? My perl executable is in c:\usr\local\bin, which can be written as /usr/local/bin for programs that understand unix-style paths. Apache, for example, is such a program and it can find perl in the correct directory based on the shebang. Since my apache executable is also on the c: drive it assumes that root / is the same as c:\.

Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by wolfi (Scribe) on Mar 21, 2004 at 02:02 UTC
    yeah - normally, windows doesn't care about #! lines (so long as the perl program doesn't either), since windows thinks in terms of file-extensions and associations. Soooo... why use it on windows? Well...

    ~ servers (even those on localhost windows) may require it. (My apache gets upset when i omit my #!C:\perl\bin\perl.exe line.)

    ~ most script problems are the same for *nix users or windows people. So, it's helpful to have one method in the posts (and easier to search for).

    ~ i'd think most perl-scripts are eventually written with the idea, that they'll eventually end up on a *nix platform. Like etcshadow said - it's a good habit.

    ~ if it's more trouble to delete/re-add/delete/re-add it as needed - rather than just having it to begin with... why omit it?

    just my take. I'd rather be writing perl code, than trying to figure out, if i needed the shebang line or not "am i only going to use this thru the prompt... or do i intend to use it thru the server...?"

    including it is just easier. :-)

      Quote: TStanley

      If I remember correctly, both Windows and Unix look on the shebang line for any switches passed in(i.e. the -w or -i switches)

      Not exactly; under Unix the shell cares for the shebang, but the Windows shells (cmd.exe, command.com) don't know anything about shebangs (only cygwin knows, off course). Perl itself cares for the parameters like -w, -n, -i, -p, ....


      Quote: wolfi

      ~ servers (even those on localhost windows) may require it. (My apache gets upset when i omit my #!C:\perl\bin\perl.exe line.)

      For Apache 1.3, there exists an option in httpd.conf which is called ScriptInterpreterSource registry. If you activate this line, Apache looks for the file extention when executed as CGI (e.g. cgi), looks up in the registry what to do with a files with the extention .cgi ... well, execute it with perl... and does it. Then you can use whatever shebang you like. I like to use this when I'm developing webpages under Windows where the production server is Linux/Unix. Another benefit is that you can test more perl-versions by just assigning another perl-interpreter to .cgi or .pl and need not changing ton's of files...

      Btw: You can associate an ending with an interpreter under windows in the shell the following way:

      assoc .pl=Perl assoc .cgi=Perl ftype Perl="D:\Programs\gnu\perl809\bin\perl.exe" "%1" %*
      (Dont forget the " in ftype, or you will get funny results if there are spaces within the paths...)

      For Apache2 there exists a similar command, but I don't know it by heart

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

        well, ya learn something new every day ;-)

        thank you for the info strat. I've done a decent amount of editting of the httpd.conf but never come across using that ScriptInterpreterSource argument.

        will have to pay more attention to that in the future. Thanks again ;-)

Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by qq (Hermit) on Mar 20, 2004 at 22:42 UTC

    maybe when you use cygwin. But then... why to /usr/bin/perl?

    Cygwin has its own root directory, so /usr/bin/perl is the correct cygwin path. To get the C: drive, you use /cygdrive/c/.

    qq

      Can't remember that. I think you're right. Well, in that case, it makes more sense to me.
Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by CountZero (Bishop) on Mar 20, 2004 at 22:34 UTC
    It gives us poor Windows users the idea that we are coding for a real OS. ;)

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Hehe... indeed poor Windows users they are :) (I'm a Windows user myself too! But I don't do weird shebangs :) )
Re: Using Perl, some Windows version and #!usr/bin/perl, WHY?
by Zero_Flop (Pilgrim) on Mar 20, 2004 at 23:12 UTC
    It might just be that perl is cross platform. In cases were you are using OS specific stuff like WIN32::OLE it is probaly habit.

    One other use however is that some editors(VIM for one) will look at the name extension to choose syntax and if the extension does not tell it what Syntax to use, then it will reference the first few lines.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://338352]
Approved by TStanley
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-06-26 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (85 votes). Check out past polls.

    Notices?