length
The number of characters in a string:
examples/length.pl
use strict; use warnings; use 5.010; use Encode; my $hi = 'HeLlo'; my $hebrew = 'שלום'; my $arabic = 'سلام'; my $smiley = '😃'; say $hi; say $hebrew; say $arabic; say $smiley; say length $hi; # 5 say length(Encode::decode('UTF-8', $hi)); # 5 say length $hebrew; # 8 say length(Encode::decode('UTF-8', $hebrew)); # 4 say length $arabic; # 8 say length(Encode::decode('UTF-8', $arabic)); # 4 say length $smiley; # 4 say length(Encode::decode('UTF-8', $smiley)); # 1
See also the explanation in String functions: length, lc, uc, index, substr.
Alternatively check out the length of an array.
Published on 2020-05-16
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post