Ad space (banner)
Lesson 12 / 20

Working with strings

This lesson covers basic string handling in Perl.

Strings come with handy built-in functions such as length (find the length), uc (convert to upper case), and substr (take a piece out).

The sample code checks the character count with length($message) and takes the first five characters with substr($message, 0, 5).

A common early stumble is that these are standalone functions rather than method calls. If you have come from an object-oriented language you will want to try $message.length(), but in Perl you write length($message).

In professional work, string handling — tidying logs, validating user input — is essential in practically every program.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Perl directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)