How to handle subroutine redefined errors in Perl

floogads picture floogads · Aug 29, 2010 · Viewed 14.2k times · Source

So I have a file that in short has this problem...

#!/usr/bin/perl -w
package Foo;

use strict;
use POSIX;

...

sub remove {
  ...
}
...

and I get a get an error saying the subroutine remove has been redefined. I know the problem, there is a subroutine called remove in POSIX. However, I don't know how to handle it. How is this problem typically solved?

Answer

mob picture mob · Aug 29, 2010

The other way to suppress this warning is to put your subroutine redefinition inside a no warnings 'redefine' block:

{
    no warnings 'redefine';
    sub remove { ... }
}