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

AI Programming as a Super Power

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:

…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:

    • Must contain .pm files

    • Must not be under .vscode/, .blib/, or versioned build folders

  • 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

You can also set environment variables to customise behaviour:

Or simulate what it would do:

Try It Yourself

The full script is available on GitHub:

👉 https://github.com/davorg/perl5lib_auto

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?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.