What is Core vs non-core modules in Perl?

In Perl, modules are divided into two main categories: core modules and non-core modules. Understanding the difference between these two can help in managing dependencies and ensuring that your Perl applications run smoothly.

Core Modules

Core modules are those that come bundled with the Perl interpreter. They are part of the standard library and are available for use without the need to install any additional software. Examples of core modules include:

  • strict - Used to enforce strict programming rules.
  • warnings - Used to enable warnings during program execution.
  • File::Basename - Used for pathname manipulations.

Non-Core Modules

Non-core modules, on the other hand, are not included with the Perl interpreter by default. They can be installed from the Comprehensive Perl Archive Network (CPAN) and provide additional functionality. Examples of non-core modules include:

  • DBI - Database Interface module for Perl.
  • Moose - A postmodern object system for Perl.
  • LWP::UserAgent - A class for web user agents.

Example

Here’s an example demonstrating the use of a core module and a non-core module:

use strict; use warnings; use DBI; # Non-core module my $dbh = DBI->connect("DBI:mysql:database=testdb", "username", "password") or die "Could not connect to database: $DBI::errstr";

Core Modules Non-Core Modules Perl CPAN DBI Programming