At $WORK, we still use Sybase ASE, a proprietary database system which has ... interesting ... requirements (heh!) on how to connect to it. It comes with its own SDK and libraries, which can't be linked statically. On MySQL/MariaDB/PostgreSQL, it's just a yum/apt/$distro_tool install away to install client libraries and you're off to the races. Even Microsoft SQL Server has a simple RPM file you can install to get at an ODBC driver that doesn't need anything more to connect to their database server. Not so with Sybase ASE, as it needs a bunch of environment variables set up before their libraries will actually work. Of course, for daily use, these are set in the shell's ~/.profile, but your ~/.profile, ~/.bash_profile, ~/.bashrc, ~/.zshrc (insert your favorite shell initialization dotfile here) is
not sourced when scripts get run from cron, systemd timers or some other job scheduling framework that just fork out to a binary directly.
So, most of our Perl scripts that touch Sybase ASE start with something like:
# We need the $SYBASE and $LD_LIBRARY_PATH environment variables to be
+ able
# to use the Sybase::Simple library (because it links to libsybct.so i
+n
# $SYBASE/$SYBASE_OCS/lib), but if we are invoked through cron, then
# ~/.profile doesn't get sourced and we are stuck with a nearly empty
+%ENV
# hash. So if we detect $SYBASE is not in %ENV, reexec through a shel
+l that
# first sources in the necessary environment variables.
unless (exists $ENV{SYBASE}) {
# $^X is the path to the current perl interpreter
# $0 is the script itself
exec '/bin/sh', '-c', ". /db/sybsdk/SYBASE.sh ; exec $^X $0 @ARGV"
+;
}
# even with the above, we need to wrap the import of the Sybase Perl
# module in a runtime block as to avoid initialization by the Perl com
+piler
# prior to runtime (which checks for the necessary $SYBASE env variabl
+es).
# See 'perldoc perlfaq8' as to the difference between 'use' and 'requi
+re'.
# Basically: 'use' is ran at compile time, 'require' at runtime.
require Sybase::Simple;
So, to this day, there most definitely is a use (heh!) for
require over
use.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.