http://qs321.pair.com?node_id=1232527


in reply to Re: some efficiency, please
in thread some efficiency, please

Thanks. There are just so many tricks I never thought of (like building the entire array into the qr statement). :)

Would have liked to have used map, but the actual data is more like:

ref 1 ref 2 1 begin end 2 begin bar end ...

with the numbers outside (right before) the beginning of each paragraph. I am sure that can be done with map, but it is a little too tricky for me at my level. :)

I killed what I had before after thirteen hours of CPU time, but I guess it (eventually) would have finished. I started it again with a print statement right before it removes each line from the file, and it starts out very quickly (just a few seconds per line removed), and then just keeps slowing down (after about a half-hour, it was well over a minute per line removed).

Still don't understand why just changing the one line:

for (@objects) { $allfile =~ s/^ +$_\n//m; }

to:

for (@objects) { $allfile =~ s/^ *(foo)? +$_\n//mn; }

caused it to slow down SO much.

Anyway, I was satisfied with the performance I had before (without the test for foo), but your method is an order of magnitude faster than that "without the test" method, and it (of course) catches the rare case when foo is there, so I am extremely grateful for that. Thanks, again.