in reply to Re: modification of read-only in hash ++
in thread modification of read-only in hash ++
I think there's a bug in Perl. Watch what happens if you dump the content of %guid in the BEGIN block:
Not only does it show that the BEGIN block doesn't autovivify the value, the error disappears as well!#!/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.
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 |