Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-24 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found