Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Supressing warnings

by morgon (Deacon)
on Jul 22, 2010 at 21:22 UTC ( #850915=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: Supressing warnings
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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-08-22 17:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (163 votes), past polls