http://www.perlmonks.org?node_id=927811


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

sub length_in_grapheme_clusters { my $length; $length++ while $_[0] =~ m/\X/g; return $length; }

As previously mentioned, this can be written as:

sub length_in_grapheme_clusters { my $length = () = $_[0] =~ /\X/g; return $length; }
or
sub length_in_grapheme_clusters { return 0+( () = $_[0] =~ /\X/g ); }

You must roll your own.

As previously mentioned, he does not need to roll his own as there's already an existing solution. (It was also mentioned that length_in_grapheme_clusters is not sufficient.)

Update: Fixed length_in_grapheme_clusters so it can be called in list context.