Although 'length ()' is the correct answer that should be used in any normal code, the horror of abigel length should be mentioned, if only for the sake of Perl lore.
Basically, the trick is to use the return value of the catch-all transliteration operator:
print "foo" =~ y===c;
y /// c replaces all characters themselves (thanks to the complement option 'c') and returns the number of characters replaced (so, in fact, the length of the string).
Yanick Oct 22 '08 at 14:19 2008-10-22 14:19
source share