Perl client prerequisites
In order run a Perl client script that connects to Vertica, your client system must have:
-
The Vertica ODBC drivers installed and configured. See Installing the Vertica Client Drivers for details.
-
A Data Source Name (DSN) containing the connection parameters for your Vertica. See Creating an ODBC Data Source Name. (Optionally, your Perl script can connect to Vertica without using a DSN as described in Connecting from Perl without a DSN).
-
A supported version of Perl installed
-
The DBI and DBD::ODBC Perl modules (see below)
Supported Perl versions
Vertica supports Perl versions 5.8 and 5.10. Versions later than 5.10 may also work.
Perl on Linux
Most Linux distributions come with Perl preinstalled. See your Linux distribution's documentation for details of installing and configuring its Perl package is it is not already installed.
To determine the Perl version on your Linux operating systems, type the following at a command prompt:
# perl -v
The system returns the version; for example:
This is perl, v5.10.0 built for x86_64-linux-thread-multi
Perl on Windows
Perl is not installed by default on Windows platforms. There are several different Perl packages you can download and install on your Windows system:
-
ActivePerl by Activestate is a commercially-supported version of Perl for Windows platforms.
-
Strawberry Perl is an open-source port of Perl for Windows.
The Perl driver modules (DBI and DBD::ODBC)
Before you can connect to Vertica using Perl, your Perl installation needs to have the Perl Database Interface module (DBI) and the Database Driver for ODBC (DBD::ODBC). These modules communicate with iODBC/unixODBC driver on UNIX operating systems or the ODBC Driver Manager for Windows operating systems.
Vertica supports the following Perl modules:
-
DBI version 1.609 (
DBI-1.609.tar.gz
) -
DBD::ODBC version 1.22 (
DBD-ODBC-1.22.tar.gz
)
Later versions of DBI and DBD::ODBC may also work.
DBI is installed by default with many Perl installations. You can test whether it is installed by executing the following command on the Linux or Windows command line:
# perl -e "use DBI;"
If the command exits without printing anything, then DBI is installed. If it prints an error, such as:
Can't locate DBI.pm in @INC (@INC contains: /usr/local/lib64/perl5/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl
/usr/lib64/perl5 /usr/share/perl5 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
then DBI is not installed.
Similarly, you can see if DBD::ODBC is installed by executing the command:
# perl -e "use DBD::ODBC;"
You can also run the following Perl script to determine if DBI and DBD::ODBC are installed. If they are, the script lists any available DSNs.
#!/usr/bin/perl
use strict;
# Attempt to load the DBI module in an eval using require. Prevents
# script from erroring out if DBI is not installed.
eval
{
require DBI;
DBI->import();
};
if ($@) {
# The eval failed, so DBI must not be installed
print "DBI module is not installed\n";
} else {
# Eval was successful, so DBI is installed
print "DBI Module is installed\n";
# List the drivers that DBI knows about.
my @drivers = DBI->available_drivers;
print "Available Drivers: \n";
foreach my $driver (@drivers) {
print "\t$driver\n";
}
# See if DBD::ODBC is installed by searching driver array.
if (grep {/ODBC/i} @drivers) {
print "\nDBD::ODBC is installed.\n";
# List the ODBC data sources (DSNs) defined on the system
print "Defined ODBC Data Sources:\n";
my @dsns = DBI->data_sources('ODBC');
foreach my $dsn (@dsns) {
print "\t$dsn\n";
}
} else {
print "DBD::ODBC is not installed\n";
}
}
The exact output of the above code will depend on the configuration of your system. The following is an example of running the code on a Windows computer:
DBI Module is installed
Available Drivers:
ADO
DBM
ExampleP
File
Gofer
ODBC
Pg
Proxy
SQLite
Sponge
mysql
DBD::ODBC is installed.
Defined ODBC Data Sources:
dbi:ODBC:dBASE Files
dbi:ODBC:Excel Files
dbi:ODBC:MS Access Database
dbi:ODBC:VerticaDSN
Installing missing Perl modules
If Perl's DBI or DBD::ODBC modules are not installed on your client system, you must install them before your Perl scripts can connect to Vertica. How you install modules depends on your Perl configuration:
-
For most Perl installations, you use the
cpan
command to install modules. If thecpan
command alias isn't installed on your system, you can try to start CPAN by using the command:perl -MCPAN -e shell
-
Some Linux distributions provide Perl modules as packages that can be installed with the system package manager (such as yum or apt). See your Linux distribution's documentation for details.
-
On ActiveState Perl for Windows, you use the Perl Package Manager (PPM) program to install Perl modules. See the Activestate's PPM documentation for details.