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:
1 |
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
cd
into a directory, if there are any validlib/
subdirectories beneath it, setPERL5LIB
automatically. -
Only include
lib/
dirs that actually contain.pm
files. -
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 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
, andforce
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
1 2 3 4 5 6 7 8 9 10 |
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:
1 2 3 4 |
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:
1 |
PERL5LIB_DRYRUN=1 cd ~/code/BigProject |
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?