Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: #!/usr/bin/perl vs. -*- perl -*-

by gone2015 (Deacon)
on Jan 20, 2009 at 18:01 UTC ( [id://737632]=note: print w/replies, xml ) Need Help??


in reply to #!/usr/bin/perl vs. -*- perl -*-

My reading of perlrun suggests that Perl's behaviour is subtle:

The #! line is always examined for switches as the line is being parsed. Thus, if you're on a machine that allows only one argument with the #! line, or worse, doesn't even recognize the #! line, you still can get consistent switch behavior regardless of how Perl was invoked...
appears to say that:

  • if you happen to be running on a system that implements the #! trick, and invoke your Perl program in a way that causes the system to use the #!, then that's fine -- you'll get as many switches and such as the system is prepared to give you.

  • however, in any event Perl will parse the #! line itself and honour switches and stuff. So, if the system doesn't do it, or you run your program by (for example) perl my_wonderful_program.pl ...., you still get the switches from the #!.

    The documentation goes on to discuss what happens if switches appear both in the command line and in the #!, and to tell you that perl needs to appear somewhere on the line for Perl to be interested in it.

So, Perl does more or less what you want. It has partly adopted the #! convention, so that even if it has no bearing on where the perl interpreter is run from, it still affects switches -- in a system independent manner.

Update: except for -T as brother Hue-Bond points out below :-(

Replies are listed 'Best First'.
Re^2: #!/usr/bin/perl vs. -*- perl -*-
by Hue-Bond (Priest) on Jan 21, 2009 at 16:07 UTC
    • however, in any event Perl will parse the #! line itself and honour switches and stuff. So, if the system doesn't do it, or you run your program by (for example) perl my_wonderful_program.pl ...., you still get the switches from the #!.

    Yes but the -T switch wants to be in the command line too. perldiag explains that this is because when perl sees the -T switch, it's too late to taint some things.

    --
    David Serrano

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found