Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Length of a string in Perl6

by lidden (Curate)
on Aug 21, 2008 at 16:55 UTC ( #705871=note: print w/replies, xml ) Need Help??


in reply to Length of a string in Perl6

Length is too ambiguous and has been dropped from the language. use $string.bytes instead, there is also codepoints, graphemes and elemes methods. elems is for array elements.

Replies are listed 'Best First'.
Re^2: Length of a string in Perl6
by jethro (Monsignor) on Aug 21, 2008 at 17:09 UTC
    There seems to be also $string.chars which sounds like the better substitute in the majority of use cases. Most of the time you want to know how long the string will be on your text terminal. At the moment it is an alias of grapheme, but who wants to write grapheme all the time?
      "chars" is only slightly shorter than "graphs" (one byte (utf-8), codepoint and grapheme ;-).

      I think in general it pays off to think about which kind of length you want. If you want to insert stuff into a database, and have to care about size limits, you'll probably care more about bytes or codepoints (depends on how well your DBMS handles Unicode).

      But you're right, most of the time the programmer is interested in graphemes when dealing with text processing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2023-12-11 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?