http://www.perlmonks.org?node_id=850918


in reply to Re^2: Supressing warnings
in thread Supressing warnings

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.)

Replies are listed 'Best First'.
Re^4: Supressing warnings
by morgon (Priest) on Jul 22, 2010 at 23:27 UTC
    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 .

Re^4: Supressing warnings
by morgon (Priest) on Jul 22, 2010 at 23:41 UTC
    #!/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