What "existing solution"?
See Re: Trying to determine the output length of a Unicode string
And why isn't length_in_grapheme_clusters() sufficient?
See Re: Trying to determine the output length of a Unicode string
I used in my Perl script is attributable to Tom Christiansen.
Then you should find his comments about Text::Wrap as they are pertinent here. Maybe it was on the Perl5 Porters mailing list (which is archived).
To be honest, I don't understand how it works
Most people will say the same about Perl, map, etc, but that's a stupid reason not to use Perl, map, etc. Especially where performance matters, which is likely for this function.
What I used: ()= returns the length of the list returned by the expression that follows (when used in scalar context).
How it works: List assignmemt in scalar context returns the number of elements to which the RHS evaluated.
Your version is tricky and obfuscated
It's actually very straightforward. There's nothing hidden, it uses well known idioms, and it require only the lowest mental load (only need to remember one value at a time).
I'd have to read the Perl documentation.
Really? I use list assignment in scalar context countless times a day. More often than the match operator, I dare say.
Your implication that someone needs to read the docs for that, but not for \X and capture-less m/.../g is unconvincing.
In reply to Re^4: Trying to determine the output length of a Unicode string
by ikegami
in thread Trying to determine the output length of a Unicode string
by pierswalter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |