http://www.perlmonks.org?node_id=442693


in reply to Stupid mistakes I repeatedly make

my %hash = { };

I found this used several times in code we'd hired some contractors to do. The infuriating thing was that it actually seems to work... so I ended up looking like a weenie when complaining about the quality of the code.

Replies are listed 'Best First'.
Re^2: Stupid mistakes I repeatedly make
by tlm (Prior) on Mar 28, 2005 at 02:40 UTC

    my %hash = { };
    I found this used several times in code we'd hired some contractors to do. The infuriating thing was that it actually seems to work...

    You need to start using the -w flag more, my friend (that or use warnings). If you had, then perl would have warned you:

    % perl -we 'my %hash = { }' Reference found where even-sized list expected at -e line 1.

    the lowliest monk

Re^2: Stupid mistakes I repeatedly make
by revdiablo (Prior) on Mar 28, 2005 at 00:57 UTC
    The infuriating thing was that it actually seems to work

    Sure, it "works", but it's certainly not right:

    $ perl -MData::Dumper -we 'my %hash = {}; print Dumper \%hash' Reference found where even-sized list expected at -e line 1. $VAR1 = { 'HASH(0x814cc20)' => undef };

    It generates a warning and adds a useless entry to the hash. I can't imagine that's what the contractors wanted to do. :-)