|Perl Monk, Perl Meditation|
Is not $_ aliased to the function argument? Why using all those references and dereferences?
Yes, it is aliased. But many people, including myself to some degree, have an aversion to using $_[n] in subroutines and will routinely change them to named vars if the subroutines become more complex than simple one liners.
Hence, when it is important to avoid copying scalar arguments, I prefer to use explicit references rather than implicit aliasing.
Moreover, running your code with N=2**29, I am still getting
I have no explanation for that. This is 5.18, with single and long excluded because they just take too long to run on strings of this length:
On my machine tr/// wins hands down for these longer lengths. Which is what I would expect everywhere.
It really surprises me that sub str does as well as it does for as long as it does given this complexity of opcodes from the explicit loop:
Compared the implicit loop of translate:
And str() is still somewhat light on logic as it currently makes no attempt to deal with misalignments between the string length and the buffer size. I haven't checked to see what effect that has on the length of the string.
Why you would get different results to me for these large size strings; I cannot begin to guess?
With 2**30, it dies with Substitution loop at ./7.pl line 10.
I never saw that because I disabled that test along with single (for taking too long) before the error ever manifest itself.
I can confirm that I also get the error message once the length of the string moves above 2**29:
I have no idea what it means?
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.