PERL code snippets24 Apr 2006 03:14 pm
Length
The length function simply gives you back the number of characters in a string variable. This is handy when you don't know the value of the variable but would like to know the number of characters it has. It is useful with arrays, conditional statements, loops, and such things.
So, if you had a variable named $gold and its value was the string "precious", you could get the length of the string "precious" with the length function:
CODE:
-
$gold="precious";
-
$length_gold = length ($gold);
Since the string "precious" has 8 characters, $length_gold variable will be 8.