in reply to modification of read-only in hash ++

A few other notes:
my $x=5; BEGIN {$y=sub{my $r=sub{$x++;warn "sub: $x"};$r->()}} $y->(); #sub: 1 at temp.pl line 2. #deref sub that derefs sub, my before BEGIN, using scalars => autoviv BEGIN {$y=sub{my $r=sub{$x++;warn "sub: $x"};$r->()}} my $x=5; $y->(); #sub: 1 at temp.pl line 1. #deref sub that derefs sub, BEGIN before my, using scalars => autoviv my %x=(1=>5); BEGIN {$y=sub{my $r=sub{$x{1}++;warn "sub: $x{1}"};$r->()}} $y->(); #Modification of a read-only value attempted at temp.pl line 2. #deref sub that derefs sub, my before BEGIN, using hash => ERROR BEGIN {$y=sub{my $r=sub{$x{1}++;warn "sub: $x{1}"};$r->()}} my %x=(1=>5); $y->(); #sub: 1 at temp.pl line 1. #deref sub that derefs sub, BEGIN before my, using hash => autoviv my %x=(1=>5); BEGIN {$y=sub{$x{1}++;warn "sub: $x{1}";}} $y->(); #sub: 6 at temp.pl line 2. #deref sub, my before BEGIN, using hash => uses main's my variable BEGIN {$y=sub{$x{1}++;warn "sub: $x{1}";}} my %x=(1=>5); $y->(); #sub: 1 at temp.pl line 1. #deref sub, BEGIN before my, using hash => autoviv my $x=5; BEGIN {$y=sub{$x++;warn "sub: $x"}} $y->(); #sub: 6 at temp.pl line 2. #deref sub, my before BEGIN, using scalar => uses main's my variable BEGIN {$y=sub{$x++;warn "sub: $x"}} my $x=5; $y->(); #sub: 1 at temp.pl line 1. #deref sub, BEGIN before my, using scalar => autoviv
my head hurts! I'm getting in over my head when it comes to understanding when subs should see "my" variables. Could someone explain what results I should expect?

I don't know how to submit a bug report so please feel free to submit one using my test cases.

AS 5.8.2 808 / win2k

--

flounder

Replies are listed 'Best First'.
Re: Re: modification of read-only in hash ++
by ysth (Canon) on Feb 05, 2004 at 17:15 UTC
    Then this is a wonderful time to learn how to submit a bug report! It takes just a few minutes; start by reading perldoc perlbug.