in reply to Re: Q on HTML::Element recursive lambda comment
in thread Q on HTML::Element recursive lambda comment

For what it's worth, I just tried abusing my laptop with this code:
use strict; use HTML::Element; sub funny { my $counter = 'x0000'; my $give_id; $give_id = sub { my $x = $_[0]; $x->attr('id', $counter++) unless defined $x->attr('id'); foreach my $c ($x->content_list) { $give_id->($c) if ref $c; # ignore text nodes } }; $give_id->($_[0]); undef $give_id; ##### Remove for evil effects ##### } my $a = HTML::Element->new('a', href => 'http://www.perl.com/'); print "Start: ", scalar(localtime), "\n"; for my $i (0..1_000_000) { funny($a); } print "Finish: ", scalar(localtime), "\n";
With the undef in place, the difference between the "Start" and "Finish" times was 15 seconds. With the undef commented out, the difference between "Start" and "Finish" was only a little over a minute (1:04); however, five minutes after printing the "Finish" line my laptop was still swapping like mad and the shell prompt hadn't yet come back - this indicates that perl was having a devil of a time cleaning things up on exit. (I just gave up and hit Ctrl-C at that point)

Incidentally, while the version without an undef was running, it took a full 30 seconds for my laptop to display the Ctrl-Alt-Del screen after I gave it the three-finger salute.

I'm not going to try the 16_000_000 times I suggested above.