in reply to Re: modification of read-only in hash ++
in thread modification of read-only in hash ++

I don't understand. Why would $guid{218827} be auto-vivified? Note that $guid{218827} is referenced from a subroutine, which isn't executed until after the BEGIN block.

I think there's a bug in Perl. Watch what happens if you dump the content of %guid in the BEGIN block:

#!/usr/bin/perl use warnings; my %guid=(218827=>5,109940=>2); BEGIN { %handle= ( cmd => sub { my $ref = sub{$guid{218827}++;warn "sub: $guid{218827}";}; $ref->(); }, ); while (my ($key, $value) = each %guid) { print defined $key ? $key : "UNDEF"; print ":"; print defined $value ? $value : "UNDEF"; print "\n"; } } $handle{cmd}->(); __END__ sub: 6 at buu line 14.
Not only does it show that the BEGIN block doesn't autovivify the value, the error disappears as well!

In fact, just about any reference to %guid (like keys %guid;, %guid;, or $guid {1};) after the assignment to %handle makes the error go away.

This ought to be perlbugged.

Abigail

Replies are listed 'Best First'.
Re: Re: modification of read-only in hash ++
by ysth (Canon) on Feb 05, 2004 at 17:17 UTC
    It appears to be fixed in bleadperl. Nevertheless, a bug report with a short test case (or patch to the t/op/closure.t) would be good.