Что такое Perl-эквивалент strlen()
?
perldoc -f length length EXPR length Returns the length in characters of the value of EXPR. If EXPR is omitted, returns length of $_. Note that this cannot be used on an entire array or hash to find out how many elements these have. For that, use "scalar @array" and "scalar keys %hash" respectively. Note the characters: if the EXPR is in Unicode, you will get the num- ber of characters, not the number of bytes. To get the length in bytes, use "do { use bytes; length(EXPR) }", see bytes.
Хотя 'length()' является правильным ответом, который должен использоваться в любом нормальном коде, ужас длины абигелей следует упомянуть, если только ради Perl lore.
В принципе, трюк состоит в использовании возвращаемого значения оператора транслитерации catch-all:
print "foo" =~ y===c; # prints 3
y///c заменяет все символы самим (благодаря опции дополнения 'c') и возвращает количество замененных символов (так, фактически, длина строки).
length($string)