DEV Community

Cover image for Turning AI into a Developer Superpower: The PERL5LIB Auto-Setter
Dave Cross
Dave Cross

Posted on • Originally published at perlhacks.com on

1

Turning AI into a Developer Superpower: The PERL5LIB Auto-Setter

Like most developers, I have a mental folder labelled “useful little tools I’ll probably never build.” Small utilities, quality-of-life scripts, automations — they’d save time, but not enough to justify the overhead of building them. So they stay stuck in limbo.

That changed when I started using AI as a regular part of my development workflow.

Now, when I hit one of those recurring minor annoyances — something just frictiony enough to slow me down — I open a ChatGPT tab. Twenty minutes later, I usually have a working solution. Not always perfect, but almost always 90% of the way there. And once that initial burst of momentum is going, finishing it off is easy.

It’s not quite mind-reading. But it is like having a superpowered pair programmer on tap.

The Problem

Obviously, I do a lot of Perl development. When working on a Perl project, it’s common to have one or more lib/ directories in the repo that contain the project’s modules. To run test scripts or local tools, I often need to set the PERL5LIB environment variable so that Perl can find those modules.

But I’ve got a lot of Perl projects — often nested in folders like ~/git, and sometimes with extra lib/ directories for testing or shared code. And I switch between them frequently. Typing:

export PERL5LIB=lib
Enter fullscreen mode Exit fullscreen mode

…over and over gets boring fast. And worse, if you forget to do it, your test script breaks with a misleading “Can’t locate Foo/Bar.pm” error.

What I wanted was this:

  • Every time I cd into a directory, if there are any valid lib/ subdirectories beneath it, set PERL5LIB automatically.

  • Only include lib/ dirs that actually contain .pm files.

  • Skip junk like .vscode, blib, and old release folders like MyModule-1.23/.

  • Don’t scan the entire world if I cd ~/git, which contains hundreds of repos.

  • Show me what it’s doing, and let me test it in dry-run mode.

The Solution

With ChatGPT, I built a drop-in Bash function in about half an hour that does exactly that. It’s now saved as perl5lib_auto.sh, and it:

  • Wraps cd() to trigger a scan after every directory change

  • Finds all qualifying lib/ directories beneath the current directory

  • Filters them using simple rules:

  • Excludes specific top-level directories (like ~/git) by default

  • Lets you configure everything via environment variables

  • Offers verbose, dry-run, and force modes

  • Can append to or overwrite your existing PERL5LIB

You drop it in your ~/.bashrc (or wherever you like), and your shell just becomes a little bit smarter.

Usage Example

source ~/bin/perl5lib_auto.sh

cd ~/code/MyModule
# => PERL5LIB set to: /home/user/code/MyModule/lib

PERL5LIB_VERBOSE=1 cd ~/code/AnotherApp
# => [PERL5LIB] Found 2 eligible lib dir(s):
# => /home/user/code/AnotherApp/lib
# => /home/user/code/AnotherApp/t/lib
# => PERL5LIB set to: /home/user/code/AnotherApp/lib:/home/user/code/AnotherApp/t/lib
Enter fullscreen mode Exit fullscreen mode

You can also set environment variables to customise behaviour:

export PERL5LIB_EXCLUDE_DIRS="$HOME/git:$HOME/legacy"
export PERL5LIB_EXCLUDE_PATTERNS=".vscode:blib"
export PERL5LIB_LIB_CAP=5
export PERL5LIB_APPEND=1
Enter fullscreen mode Exit fullscreen mode

Or simulate what it would do:

PERL5LIB_DRYRUN=1 cd ~/code/BigProject
Enter fullscreen mode Exit fullscreen mode

Try It Yourself

The full script is available on GitHub:

I’d love to hear how you use it — or how you’d improve it. Feel free to:

  • ⭐ Star the repo

  • 🐛 Open issues for suggestions or bugs

  • 🔀 Send pull requests with fixes, improvements, or completely new ideas

It’s a small tool, but it’s already saved me a surprising amount of friction. If you’re a Perl hacker who jumps between projects regularly, give it a try — and maybe give AI co-coding a try too while you’re at it.

What useful little utilities have you written with help from an AI pair-programmer?


The post Turning AI into a Developer Superpower: The PERL5LIB Auto-Setter first appeared on Perl Hacks.

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!

Top comments (0)

AWS Security LIVE! Stream

Streaming live from AWS re:Inforce

Join AWS Security LIVE! at re:Inforce for real conversations with AWS Partners.

Learn More