Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: | )

Use the length function to get the number of characters of a string. Special characters, such as new line (\n) and carriage return (\r) are also included in the length calculation.

Please notice that this function works on scalar variables, you can't use it to get the number of elements of an array or a hash.

Example:

#!/usr/bin/perl
 
$line = "perl test line\n";
 
print "\$line has " . length($line) . " lines\n";