in reply to Conflict with INIT block is not an error?

I think it would be hard to make it a syntax error, as that would mean the parser would have to detect a problem when parsing the INIT token in use constant INIT => 4. The latter, though, is just a regular fat-comma-quoted string which is passed as argument to constant.pm's import function.

OTOH, constant.pm could in theory be made to croak instead of just issuing a warning, as it currently does

# Maybe the name is tolerable } elsif ($name =~ $tolerable) { # Then we'll warn only if you've asked for warnings if (warnings::enabled()) { if ($keywords{$name}) { warnings::warn("Constant name '$name' is a Perl keyword");

But maybe whoever wrote that code had some curious usage of such keyword/subroutine redefinition in mind, in which case a fatal error might be inappropriate here? After all, you can make warnings fatal yourself, as already mentioned above.

Replies are listed 'Best First'.
Re^2: Conflict with INIT block is not an error?
by ikegami (Patriarch) on Oct 26, 2010 at 16:41 UTC

    It shouldn't croak for BEGIN.

    $ perl -le'use constant BEGIN => 4; print(BEGIN);' 4

    But I'm all for having it croak for INIT.

    $ perl -le'use constant INIT => 4; print(INIT);' Undefined subroutine &IO::File::AUTOLOAD called. INIT failed--call queue aborted.

    A bug report can be filed.