Perl Libraries
Routines used in several scripts are often put into libraries, which are then included in the scripts with the use directive. The standard library folders differ between platforms, Linux distributions and Perl versions. Since those directories often require root access, I place my personal libraries in ~/bin/perllib, which is looked into by all my scripts. To be on the safe side, my scripts also search in the directory they're living at, so you can simply put them all in ~/bin if you like.
My scripts usually require at least DebugPrint.pm and GetParameters.pm.
GetParameters.pm
The most popular library to parse command line parameters given to a Perl script is GetOpt::EvaP. However, since it was for my purposes a bit too powerful (and hence complicated to use) and because I needed some specific things, I decided to write my own little parser.
Download GetParameters.pm (source)
Download GetParameters.pdf (documentation)
ReadLatex.pm
Download ReadLatex.pm (source)
I use LaTeX to create high-quality reports on chemical calculations in an automated fashion via scripts. For that, I often have to read in and change things in LaTeX documents and, therefore, wrote the following function to make that easy:
@LaTeX = ReadLatex ("file.tex");
This does all the overhead stuff like checking for the file, opening and reading it. The bonus and reason of existence is that include directives in the TeX file are taken into account. The returned array contains the complete source of the file, even if it was split up into several parts.
DebugPrint.pm
Download DebugPrint.pm (source)
Just a little routine I wrote out of laziness and to which I got so used to that I include it by default in every script.
While coding, you very often have to dump out variables to check their contents. This becomes tiresome if you use complex data structures (such as arrays of arrays). The function dp simply takes a list of variables, dumps them all and stops processing the script. If you are dealing with very large structures, the function dpf dumps all into the file debug.txt.
dp ($Counter, \@Content, \%Users);
Just remember to pass arrays and hashes as references to the script.
|
|
|
|
|