String Functions

There is a close relationship between an operator and a function. For example, Perl uses ** for exponentiation, whereas some languages use the pow function to achieve the same result. Likewise, Perl uses the % symbol for the remaindering operation, while other languages use the MOD function to achieve the same result. Thus, in this section we present some simple but useful functions that you can use on scalars.

The length Function

The length function returns the length of a scalar.

$string="This\tstring\nconsists\nof a few\nlines\n";
$len = length($string);                 #    length = 36

Remember that the \t sequence represents the tab character and the \n sequence represents the newline character. Thus, each of these sequences counts as a ...

Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.