Missing Import Errors in Perl
Perl's Can't locate X.pm in @INC and Undefined subroutine &X::y called errors indicate missing modules or incorrect imports.
Install the Module
# Using cpanm (recommended)
cpanm JSON::XS
cpanm Moo
# Using CPAN shell
cpan install JSON::XSuse vs require
# use — compile-time import (preferred)
use JSON::XS;
use List::Util qw(sum max min);
# require — runtime import
require JSON::XS;
# Must call with full package name:
JSON::XS::encode_json($data);@INC Path Issues
If the module exists but Perl can't find it:
# Add a directory to the search path
use lib '/path/to/my/modules';
use lib './lib';
use MyApp::Utils; # Found in ./lib/MyApp/Utils.pmOr from the command line:
perl -I./lib script.plImporting Specific Functions
# Import nothing (OO interface)
use HTTP::Tiny;
my $http = HTTP::Tiny->new;
# Import specific functions
use File::Path qw(make_path remove_tree);
make_path('a/b/c');
# Import everything (avoid)
use POSIX; # Imports hundreds of symbolsVersion Requirements
use Scalar::Util 1.50 qw(blessed weaken);
# Dies if Scalar::Util < 1.50Carton (Perl's bundler)
# cpanfile
requires 'Mojo::Pg', '4.27';
requires 'JSON::XS';
# Install
carton install
carton exec perl app.plBugsly captures runtime Can't locate errors with the full @INC path, helping you diagnose module installation issues in production containers.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Fix Missing Import in Ruby
Resolve LoadError and NameError in Ruby scripts by fixing require statements, gem installations, and $LOAD_PATH configuration.
Read moreHow to Fix Validation Error in Clojure
Struggling with Validation Error in Clojure? This guide explains why it happens and how to resolve it quickly.
Read moreFix AuthenticationError Error in Flask — When Deploying
Learn how to fix the AuthenticationError error in Flask when deploying. Step-by-step guide with code examples and solutions.
Read moreHow to Fix File Not Found Error in C#
Learn how to fix the File Not Found Error in C#. Step-by-step guide with code examples.
Read more