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.