At 01:08 PM 7/11/2002 -0700, Ashley Winters wrote: >On Thursday 11 July 2002 11:47 am, Chip Salzenberg wrote: > > According to Dan Sugalski: > > > At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote: > > > > 3a. If so, how can one distinguish among the e.g. many C<my $foo> > > > > variables declared within the current function? > > > > > > One pad per block, rather than per sub. > > > > I just remembered why I thought that woundn't work: BEGIN is a block. > > > > my $x = 1; > > BEGIN { %MY::{'$y'} = \$x } > > print $y; > >Even worse, you should be able to modify lexicals even outside your scope. > >sub violate_me { > caller(1).MY{'$y'} := caller(1).MY{'$x'}; # hypothetical syntax >} > >{ > my $x = 1; > my $y; # Might be able to BEGIN { violate_me() } instead > violate_me(); > print $y; >}
This reminds me why I don't use Perl4 'local' anymore. And now we have even uglier ways to write poor code. :) The only real use I can see of %MY is debugging. If people are going to take handles to pads and modify lexicals in closures, continuations and routines from the outside, it probably means that the item needs to be a class. And side effects like "I call you, you modify me invisibly...." seems more like taking dangerous drugs than programming. Yep, I warned you about calling that routine, now look what it did to your brains. -Melvin