Tags
webcam vindaloo vim version vegan unix unicef trojan todo tmux thinkpad textmate testing tagging syntax svn sugar subversion stubbing sphinx spam spaces solaris sitemap site sinatra shoulda sheet set security search schema_info SchemaInfo ruby rinari restaurant relationships refresh rdiff-backup ramaze railsconf08 railsconf07 rails protools production power placeboeffect pink floyd PIC perl overheat outbreak osx os x NYHS NYC nginx netbeans nested nanophotonics mysql music MPEG-4 mongrel model migration microvolunteer macbook mac logrotate logic log linux less leopard keynote JAX javascript java jacksonville iterm2 iterm imunizator highlighting hanna Handbrake haml hacks google geocoding genghistron gem gaming gabrielle's funny functional fun friends food fixesThe Fixer said over 5 years ago permalink Comment? (0)
Tagged: perl
Perl use lib
I recently had occasion to break up an overly-large Perl script into a couple of modules, but I didn’t particularly want to install the modules anyplace. For one thing, I’m still working on them, but I also want to use a current (working!) version in production. Keeping the modules next to the script seemed like a nice straightforward thing to do, and it even worked, so long as the current working directory was the same as the directory the script and its modules were located in, but didn’t work so well from a different directory.
The solution is the FindBin module, which has some heuristics to find where the currently running script is actually located, and make that directory available to the rest of the program as a nice neat variable. Here’s what bit me; the syntax to actually make use of this looks like this:
use FindBin; use lib "$FindBin::Bin";
What I failed to notice is that the second line is NOT a fill-in-the-name-of-your-library-here thing, it’s a literal thing. It is supposed to be followed by code that actually loads the libraries you want, only now it will look in the same directory as where the script is loaded from as well.
use FindBin; use lib "$FindBin::Bin"; use MyLibrary; use MyOtherLibrary;
“use lib” is not a command to load a library, it’s a “pragma”, which alters the way Perl works. Yet another bit of the whale guts in Perl, I suppose. Since I don’t write in Perl all that often, I suppose I really ought to dig out my copy of the camel book and keep it in a more accessible place so I don’t embarrass myself like this every time I try.