in reply to Using substr to split a string scales as N^2 -- alternatives?

The best workaround I've found is to modify the string in-place by using the 4-arg substr. This effectively just adjusts a pointer and a couple of offsets, and so runs 1000x faster:

c:\test>TimeIt \perl\bin\perl.exe -e"$a = 'a' x 800_000; substr($a, 0, 1, '') while length($a);" Kernel: 0.00000 User: 0.26563 Total: 0.26563

Unfortunately, it isn't a good substitute for the lvalue ref problem.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."