in reply to An Interesting Gotcha With use/require

Subroutine fileparse_set_fstype redefined at C:/Program Files/Perl/lib/File/Basename.pm line 152 (#1) (W redefine) You redefined a subroutine. To suppress this warning +, say { no warnings; eval "sub name { ... }"; }

Out of interest, does anyone know why the error message suggests wrapping "sub name { ... }" in an eval?

use strict; use warnings; sub foo { print 'x' } { no warnings; sub foo { print 'y' } } foo();
...prints 'y' with no warnings for me.

Replies are listed 'Best First'.
Re^2: An Interesting Gotcha With use/require
by lestrrat (Deacon) on Feb 10, 2005 at 06:37 UTC

    In your code, the first and second sub are declared at compile time. But if you want to dynamically declare a subroutine at run time, you need to wrap it up in an eval block so that that particular piece of code is evaluated only at run time.