overriding perl switch

S

sravi

I have a perl switch -w in my program
#!/usr/bin/perl -w

If i invoke this program, from the shell it is invoked with -w switch.
Is there a way i can override this? That is i should be able to invoke
this without -w switch.

If i invoke this script like this
/usr/bin/perl <script>
the -w switch is also enabled. Is there a way to override this? Please
help.
 
J

John Bokma

sravi said:
I have a perl switch -w in my program
#!/usr/bin/perl -w

If i invoke this program, from the shell it is invoked with -w switch.
Is there a way i can override this? That is i should be able to invoke
this without -w switch.

If i invoke this script like this
/usr/bin/perl <script>
the -w switch is also enabled. Is there a way to override this? Please
help.

Your script runs with -w (use strict; is recommended afaik), so why on
Earth do you want to disable it?

Please don't tell it sometimes doesn't work with -w and hence that's the
reason you want to disable it?
 
S

sravi

my intention is not to remove -w switch(just an example) but use
someother switches, which will override the existing switch
 
J

John Bokma

sravi said:
my intention is not to remove -w switch(just an example) but use
someother switches, which will override the existing switch

Please quote at least a part of the posting you are replying to.

Why on Earth do you want to override the -w switch? I guess you have an X Y
problem. You think you want X, but really you are looking for Y.
 
A

Anno Siegel

sravi said:
my intention is not to remove -w switch(just an example) but use
someother switches, which will override the existing switch

Then why do you waste the groups time by asking a question you don't
want the answer to?

Anno
 
A

Anno Siegel

Abigail said:
sravi ([email protected]) wrote on MMMMLXVI September MCMXCIII in
<URL:%% I have a perl switch -w in my program
%% #!/usr/bin/perl -w
%%
%% If i invoke this program, from the shell it is invoked with -w switch.
%% Is there a way i can override this? That is i should be able to invoke
%% this without -w switch.
%%
%% If i invoke this script like this
%% /usr/bin/perl <script>
%% the -w switch is also enabled. Is there a way to override this? Please
%% help.


$^W = 0;

See 'man perlvar'.

I think the OP wants to countermand the switch without touching the
program text.

perl -M-warnings script
I do wonder why you want to turn off warnings though. That doesn't
sound like a good idea.

As has been revealed, the poster asked about -w, but wants to revoke
a different, as yet undisclosed, switch. What silliness...

Anno
 
T

Tad McClellan

John Bokma said:
Please don't tell it sometimes doesn't work with -w


If so, then it will also sometimes _work_ with -w since warnings
don't change the execution of the program. It just makes some
additional output on STDERR.

If it works with warnings it will work without warnings.

If it does not work with warnings, it will not work without warnings
(but you may get a clue as to why it is not working).
 
J

John Bokma

Anno said:
As has been revealed, the poster asked about -w, but wants to revoke
a different, as yet undisclosed, switch. What silliness...

Let me guess... let me guess :)

The -T, because the OP discovered that

perl somecoolscript.cgi

Gave a warning about taint too late...

Well, just try

perl -T somecoolscript.cgi.
 
J

J. Romano

sravi said:
I have a perl switch -w in my program
#!/usr/bin/perl -w

If i invoke this program, from the shell it is invoked
with -w switch. Is there a way i can override this?
That is i should be able to invoke this without -w switch.

If i invoke this script like this
/usr/bin/perl <script>
the -w switch is also enabled. Is there a way to override
this? Please help.


Dear sravi,

I'm giving you a response based on the assumption that you want to
know how to override any switch, not just the -w switch.

Of course, the obvious way to "undo" a switch is to use your
favorite text editor and remove that switch manually. Save your
changes, and viola'! The switch is no more!

Granted, you may want to just suppress the switch's behavior
without editing the file. I question why you would want to do this,
but in case you really, really want to, here is a way you can suppress
all the switches:

Say that you want to run a script called myscript.pl as if it didn't
have any switches. You can run it like this:

perl -pe "BEGIN{<>}" myscript.pl | perl

I still wonder why you would want to disable certain switches in a
Perl script. Whatever the reason, if you should use this approach and
end up making things worse for yourself (due to the fact that undo-ing
the switches often causes more harm than good), you have nobody to
blame but yourself. In other words, I recommend against disabling any
switch you didn't put in yourself.

-- J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top