DEV Community


Posted on

Perl tips I wish I knew as a beginner

I think the hard part with Perl and other languages, is setting up your environment. As you do more Perl you realize there are better ways to do things that aren't straight forward when you first began the journey.

Disclaimer: I use Linux and this will be on a Linux environment, BUT with WSL on windows and with homebrew on mac.

System Perl and User Perl

On Linux, we have a system Perl. It's great to have but we don't want to mess with it. Lets keep the system Perl for the system. We want a user environment and you really must do this, its way better. We have two tools we can pick from that make it easy to get started.

Plenv and Perlbrew. I started on Perlbrew and moved over to Plenv.

Plenv allows you to make it so each project you work on has a .plenv file and you can specify the Perl version you want.

Look at the two links, pick one and set it up, pick a perl version and install it. Verify it works with perl -v.

You want to install cpanminus.
plenv install-cpanm <--plenv
cpan App-cpanminus

You are now off system Perl and on your user Perl, its awesome. Cpanminus is installed and you can now install Perl modules for your project.

The cpanfile

In your project you want to make a cpanfile. Cpanfiles contain a list of Perl modules.

As your project grows, add in the modules to the cpanfile. When you need to distribute it, you can use the below command to install the dependencies. Makes life easier for everyone.
cpanm --installdeps .


"Perl module dependency manager (aka Bundler for Perl)"
Carton is awesome, with plenv its even more awesome.

This is stolen from metacpan pod:

# On your development environment
> cat cpanfile
requires 'Plack', '0.9980';
requires 'Starman', '0.2000';

> carton install
> git add cpanfile cpanfile.snapshot
> git commit -m "add Plack and Starman"

# Other developer's machine, or on a deployment box
> carton install
> carton exec starman -p 8080 myapp.psgi
Enter fullscreen mode Exit fullscreen mode


Before vscode came out, I was living in PHPStorm with a Perl plugin, it worked but it was only okay. Code is awesome with all its plugins, once you get code up, browse the perl plugins. One you will want to have is perltidy and you'll need a .perltidyrc in your project, you can find examples on the web, but here is Mojolicoius perltidyrc. I use that one.

This should get you started with Perl.

Top comments (0)