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
…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
cdinto a directory, if there are any validlib/subdirectories beneath it, setPERL5LIBautomatically.Only include
lib/dirs that actually contain.pmfiles.Skip junk like
.vscode,blib, and old release folders likeMyModule-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 changeFinds all qualifying
lib/directories beneath the current directoryFilters them using simple rules:
Excludes specific top-level directories (like
~/git) by defaultLets you configure everything via environment variables
Offers
verbose,dry-run, andforcemodesCan 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
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
Or simulate what it would do:
PERL5LIB_DRYRUN=1 cd ~/code/BigProject
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.
Top comments (0)