http://qs1969.pair.com?node_id=850915


in reply to Re: Supressing warnings
in thread Supressing warnings

The #! line is always examined for switches as the line is being parsed.

Funny, I never knew that. It does not even need to contain a path to perl, all it needs is an occurance of the string "perl".

If a.pl e.g. starts with "#!end lines properly! -d", then "perl a.pl" starts the debugger.

I hope I find a way to turn this knowledge into a beer at the upcoming YAPC::Europe (even though I think this behavour does not really makes sense).

Replies are listed 'Best First'.
Re^3: Supressing warnings
by almut (Canon) on Jul 22, 2010 at 21:39 UTC
    I think this behavour does not really makes sense

    I'd say it makes a lot of sense :)

    (For example, at 5.8 times when there was no say, -l was one of my favorite options to put in the shebang line for short test scripts.)

      Yeah, ok there may be some uses like yours (which I would consider a hack), but in general (at least that would be the behaviour of least surprise) you (ok: I) would expect that when you run a script as "a.pl" you get your command-line flags from the shebang-line and when you run it as "perl <whatever flags> a.pl" your get it from - well - the command line.

      With this behaviour I cannot run a script with different flags without having to modify it if it contains a shebang lines with flags.

      Do Python and Ruby do this as well?

        With this behaviour I cannot run a script with different flags without having to modify it if it contains a shebang lines with flags.

        You could also argue the other way round, i.e. it provides for consistency independently of how exactly the interpreter is being invoked — in particular as there are some operating system that don't handle shebangs (one rather commonly used one is among them...).

        And some options might be an integral part of a script, or at least important to its proper functioning — like -n, -p, -l, -C (which didn't work on the shebang line until recently, btw), etc. — so I would rather want them to remain in effect when I call the script as perl myscript.pl .

      #!/home/mh/perl512/bin/perl -w warn "Hubba\n"; # script a.pl, produces warning

      When you run this as "perl -X a.pl" you still get the warning - even though -X should disable them.

      Is that because -w (from shebang) is "stronger" than -X (from command line)?

      UPDATE:

      The above is crap - sorry.

        I think the reason Morgon says it's crap is because -w has no effect on warn. If you change the test to actually produce a warning, then the -X on the command line is indeed "stronger" than the -w in the shebang, but that's because the -X is always stronger than the -w, even if they swap places, or are both together on the command line or both together in the shebang.



        - Boldra