I wanted to be able to do this in Perl (the code below is Python lol)
try:
import Module
except:
print \"You need module Module to run this program.\"
>
There are many modules for doing that; see the list of CPAN modules that (can) load other modules. However, it is a bit risky to rely on an external module (what if it is not present?). Well, at least, if you rely on Moose, Class::Load can be used safely as it is Moose's prerequisite:
#!/usr/bin/env perl
use strict;
use utf8;
use warnings qw(all);
use Class::Load qw(try_load_class);
try_load_class('Module')
or die "You need module Module to run this program.";