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?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
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
In reply to Re: modification of read-only in hash ++
by flounder99
in thread modification of read-only in hash ++
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |