NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Re: (Score:1)
Re: (Score:1)
D:\Development>perl -MDDS -e"my $closure=do{ my $x=100; sub { $x++ } }; Dump $closure"
my ($x);
$x = 100;
$CODE1 = sub {
$x++;
};
I can break this... (Score:1)
After some thinking, the only strategy that looks like it would work perfectly is to go to a nested data structure in the event of collisions. You could do that like this. Suppose that you had multiple closures pointed at $foo. Then make $foo an anonymous array of scalars and make the closures each point at $foo->[$i] where $i is an index. In the case of @foo you can make it @{$foo[$i]} instead. In the case of %foo you can make it %{$foo{$i}}. In each case the eclipsing is done without accessing any other variable name that might also be accessed.
Reply to This
Parent
Re:I can break this... (Score:1)
The following code crashes.
Shoot. Yep. It does. And it highlights what I forgot to document: the subs being dumped shouldn't mix the use of dynamics and lexicals with the same name, and that its is unwise to use variables matching /_eclipse_\d+$/. (Which personally I think is not such a terrible restriction, albeit not at all ideal.)
Dealing with the former is actually very tricky, and probably wont ever be solved properly. A good example is
my $a=sub { $a++ };
The second issue regarding eclipsed