Ad space (banner)
Lesson 16 / 20

Modules and use strict / warnings

This lesson covers use strict; use warnings; — which belongs in every piece of Perl — along with how to use a module.

use strict; forbids things such as using a variable without my, and use warnings; reports suspicious code. Putting both at the top of a Perl program is treated as all but mandatory.

The sample code declares use strict; use warnings;, loads the sum function from the standard List::Util module with use List::Util qw(sum);, and totals an array.

A common early stumble is skipping these declarations. The code still runs without them, but typos and similar bugs become much harder to notice, so writing them every time is strongly recommended.

In professional work, the convention is so well established that Perl code without use strict; use warnings; gets flagged in review.

๐Ÿ“– 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)