subroutine redefined warning

J

jyothsna

How to avoid "subroutine redefined" warning in perl.
what are the possible cases of getting this warning and avoid it.
 
A

attn.steven.kuo

jyothsna said:
How to avoid "subroutine redefined" warning in perl.
what are the possible cases of getting this warning and avoid it.


The warning is issued because you redefined a
subroutine.

You can turn off the warning.
See perldoc perlexwarn.

For example:

use strict;
use warnings;

use vars qw(*foo);

sub bar {
print "bar";
}


{
no warnings 'redefine';
local *bar = sub {
print "foo";
};
bar();
}

bar();
 
P

Paul Lalli

The warning is issued because you redefined a
subroutine.

You can turn off the warning.

I would wager that about 9 times out of 10, this is the equivalent of
sticking your fingers in your ears and shouting "LA LA LA I CAN'T HEAR
YOU!!".

Don't ignore warnings. Fix them.

Figure out where you're redefining the subroutine (read the WHOLE
warning message, including the parts about line numbers and filenames),
and then decide if that's really something you wanted to do.

Paul Lalli
 
X

xhoster

jyothsna said:
How to avoid "subroutine redefined" warning in perl.

Don't redefine your subroutine. Or turn off the warning.
what are the possible cases of getting this warning and avoid it.

I usually get this warning when I abstract some common subroutine out of
many scripts, and put it into a central module. But then I find/run some
scripts which I forgot to abstract it out of, so it gets defined once in
the module and once in the script itself.

Xho
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top