[Melbourne-pm] Unexpected hashref behaviour

Wesley Moore wjmoore at gmail.com
Thu Aug 16 22:23:27 PDT 2007

Hello all,
Wondering if anyone can shed some light on the behaviour that a
colleague noticed in some of our code, replicated below. My guess is
it has something to do with elements in a foreach loop being aliases
to the real element combined with autovivification, but its just that
- a guess.


#!/bin/perl -w

use strict;
use Data::Dumper;

my $h = {};
$h->{ k } = undef;
print Dumper $h;
foreach my $k ( @{ $h->{k} } ) {}
print Dumper $h;

$ ~/perl/djp2.pl
$VAR1 = {
          'k' => undef
$VAR1 = {
          'k' => []

More information about the Melbourne-pm mailing list