The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

warnings::pedantic - Dubious warnings for dubious constructs.


Version 0.02


This module provides a pedantic warning category, which, when enabled, warns of certain extra dubious constructs.

    use warnings::pedantic;

    grep { ... } 1..10; # grep in void context
    close($fh);         # close() in void context
    print 1;            # print() in void context


Besides the pedantic category, which enables all of the following, the module also provides separate categories for individual groups of warnings:

  • void_grep

    Warns on void-context grep:

        grep /42/, @INC;
        grep { /42/ } @INC;

    This code is not particularly wrong; it's merely using grep as an alternative to a foreach loop.

  • void_close

    Warns on void-context close() and closedir():


    This is considered dubious behaviour because errors on IO operations, such as ENOSPC, are not usually caught on the operation itself, but on the close() of the related filehandle.

  • void_print

    Warns on void-context print(), printf(), and say():

  • sort_prototype

    Warns when sort()'s first argument is a subroutine with a prototype, and that prototype isn't $$.

        sub takes_a_block (&@) { ... }
        takes_a_block { stuff_here } @args;
        sort takes_a_block sub {...}, @args;

    This probably doesn't do what the author intended for it to do.

  • ref_assignment

    Warns when you attempt to assign an arrayref to an array, without using parenthesis to disambiguate:

        my @a  = [1,2,3];   # Warns; did you mean (...) instead of [...]?
        my @a2 = ([1,2,3]); # Doesn't warn

    This is a common mistake for people who've recently picked up Perl.

  • maybe_const

    Identifiers used as either hash keys or on the left hand side of the fat comma are always interpreted as barewords, even if they have a constant attached to that name:

        use constant CONSTANT => 1;
        my %x = CONSTANT => 5;      # Used as "CONSTANT"
        $x{CONSTANT} = 5;           # Ditto

    This is intended behaviour on Perl's part, but is an occasional source of bugs.

Or in tree form:

    all -+
         +- pedantic --+
                       +- void_grep
                       +- void_close
                       +- void_print
                       +- sort_prototype
                       +- ref_assignment
                       +- maybe_const

All of the warnings can be turned off with

    no warnings 'pedantic';

as well as

    no warnings;

or even

    no warnings::pedantic;

Additionally, you can turn off specific warnings with

    no warnings 'void_grep';
    no warnings 'void_close';
    no warnings 'void_print'; # printf, print, and say


Brian Fraser, <fraserbn at>


Please report any bugs or feature requests to bug-warnings-pedantic at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


The warning for void-context grep was at one point part of the Perl core, but was deemed too controversial and was removed. Ævar Arnfjörð Bjarmason recently attempted to get it back to the core as part of an RFC to extend, which in turn inspired this module.


Copyright 2014 Brian Fraser.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.