Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Trying to determine the output length of a Unicode string

by ikegami (Pope)
on Sep 26, 2011 at 19:37 UTC ( #927932=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Trying to determine the output length of a Unicode string
in thread Trying to determine the output length of a Unicode string

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.


Comment on Re^4: Trying to determine the output length of a Unicode string
Select or Download Code
Re^5: Trying to determine the output length of a Unicode string
by Jim (Curate) on Sep 26, 2011 at 20:18 UTC

    You just changed your version of length_in_grapheme_clusters() to be more like Tom Christiansen's. I told you I thought your version was "weirdly dependent on context." It was. Now it's not because you changed it to be more like the one you disparaged earlier.

    I had tested your original, uncorrected version of length_in_grapheme_clusters() in my Perl script and got results I didn't understand when I called the function in list context instead of scalar context.

      I thought your version was "weirdly dependent on context." It was.

      So what? I never said it wasn't.

      I had tested your original, uncorrected version of length_in_grapheme_clusters() in my Perl script and got results I didn't understand when I called the function in list context instead of scalar context.

      Again, so what? You said far more than that, and I responded to the rest of what you said.

      Now it's not because you changed it to be more like the one you disparaged earlier.

      No, I took no steps closer to reintroducing the silly loop.

        Your original version of the function was broken so you fixed it, yet you continue to argue that my criticism of its brokenness was wrong. It wasn't wrong. It was spot on.

        You made your version of length_in_grapheme_clusters() patently more like Tom's version when you fixed it. You even used the same scalar variable name, $length, that I used in my script!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927932]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-10-31 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (224 votes), past polls