📄 ch18.htm
字号:
<LI><TT><FONT FACE="Courier">DBD-Oracle-0.29.tar.gz</FONT></TT>
for Oracle users
<LI><TT><FONT FACE="Courier">DBD-Informix-0.20pl0.tar.gz</FONT></TT>
for Informix database users
<LI><TT><FONT FACE="Courier">DBD-QBase-0.03.tar.gz</FONT></TT>
for Quickbase users
<LI><TT><FONT FACE="Courier">DBD-mSQL-0.60pl9.tar.gz</FONT></TT>
for mSQL-based databases
<LI><TT><FONT FACE="Courier">DBI-0.67.tar.gz</FONT></TT> for the
DBI interface
</UL>
<P>
The interface packages are simply front-ends to the database engine
that you must have installed on your machine. For example, in
order to use the Oracle DBI package, you'll need the Oracle database
engine installed on your system. The installation instructions
are located in the <TT><FONT FACE="Courier">README</FONT></TT>
files in the packages themselves. You'll need to have Perl 5.002
installed on your system to get some of the packages to work,
especially the DBI module.
<P>
The DBI interface is very different than the old, database-specific
interfaces provided by oraperl, ingperl, interperl, and so on.
To simplify the transition to Perl 5, some <TT><FONT FACE="Courier">DBD::</FONT></TT>
drivers, such as <TT><FONT FACE="Courier">DBD::Oracle</FONT></TT>,
come with an extra module that emulates the old-style interface.
The DBI interface has never been fully defined because it has
been constantly evolving. This evolution will take a large step
forward with the adoption of the standard ODBC interface as the
core of the DBI. Because this redefinition of the DBI interface
standard is bound to change the DBI interface, Tim Bunce recommends
using stable emulation interfaces, such as oraperl, instead.
<H2><A NAME="RDB"><FONT SIZE=5 COLOR=#FF0000>RDB</FONT></A></H2>
<P>
The RDB database utilities for Perl deserve an honorable mention.
The RDB package is complete, simple to use, and very easy to set
up. The author of this package is Walt Hobbs; he can be reached
at <TT><FONT FACE="Courier">hobbs@rand.org</FONT></TT>.
<P>
The source and documentation is found in the file <TT><FONT FACE="Courier">RDB-2.5k.tar.Z</FONT></TT>
in the CPAN modules directories. There is a file named <TT><FONT FACE="Courier">Info.RDB</FONT></TT>
in the package that provides a short overview of how the RDB package
organizes its data and what commands are available for you to
use. The <TT><FONT FACE="Courier">Info.RDB</FONT></TT> file also
lists the origins of the RDB package, describes how to use it,
and provides a sample data file.
<P>
The operators in the RDB packages are Perl scripts that use standard
I/O for UNIX to operate on ASCII files. The format for databases
in the RDBM package is to store data in rows and columns in text
files. Each row contains items separated by tabs, and each row
is terminated by a newline character. (The field separator is
a tab, and the record separator, therefore, is the newline character.)
Each column in the text file has the items' names and format defined
as the first two rows.
<P>
Because the data is stored in such a format, it's easier to access
the data using programs other than those supplied with the RDB
package. You can use Perl or awk scripts to get what you want
if the RDM programs do not give you what you need. The RDB operators
are only Perl scripts that you can use as a basis for writing
your own extensions.
<P>
The operators on the package include listing by row, listing by
column, merging tables, and printing reports. All operators in
the RDB package read from standard input and write to standard
output.
<P>
Consider the following sample data file. There are four columns
in the data file. Each column has a heading and type of data associated
with it. The comments with <TT><FONT FACE="Courier">#</FONT></TT>
in the front of the line are ignored. The first uncommented row
contains the name of fields per column. The row immediately after
that stores the type of data. <TT><FONT FACE="Courier">4N</FONT></TT>
means that <TT><FONT FACE="Courier">LINE</FONT></TT> and <TT><FONT FACE="Courier">WORD</FONT></TT>
are four-digit wide numbers. (<TT><FONT FACE="Courier">S</FONT></TT>
specifies a string and <TT><FONT FACE="Courier">M</FONT></TT>
stands for month.) A digit by itself is a string; therefore, <TT><FONT FACE="Courier">NAME</FONT></TT>
fields are eight characters wide.
<BLOCKQUOTE>
<TT><FONT FACE="Courier">#<BR>
# Sample data file for Chapter 18<BR>
#<BR>
LINE WORD BYTE NAME
<BR>
4N 4N 5N 8
<BR>
1128 6300 37140 TS03.dat
<BR>
644 3966 24462 TS04.dat
<BR>
1175 6573 40280 TS05.dat
<BR>
968 6042 38088 TS13.dat
<BR>
687 3972 24383 TS14.dat
<BR>
741 4653 28100 TS16.dat
<BR>
1621 8804 58396 TS17.dat
<BR>
1061 6086 39001 TS20.dat
<BR>
1107 4782 29440 TS21.dat
<BR>
846 5839 37442 TS22.dat
<BR>
1758 8521 54235 TS23.dat
<BR>
836 4856 30916 TS24.dat
<BR>
1084 5742 34816 TS27.dat</FONT></TT>
</BLOCKQUOTE>
<P>
The commands to operate on are relatively simple. To sort the
table by <TT><FONT FACE="Courier">LINE</FONT></TT> numbers, you
use this command on the <TT><FONT FACE="Courier">test.data</FONT></TT>
file:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">sorttbl < test.data LINE > out</FONT></TT>
</BLOCKQUOTE>
<P>
The resulting output in the <TT><FONT FACE="Courier">out</FONT></TT>
file is as follows. The format for the output file is an RDB file
itself. You can run other RDB operators on it, too!
<BLOCKQUOTE>
<TT><FONT FACE="Courier">#<BR>
# Sample data file for Chapter 18<BR>
#<BR>
LINE WORD BYTE NAME
<BR>
4N 4N 5N 8
<BR>
644 3966 24462 TS04.dat
<BR>
687 3972 24383 TS14.dat
<BR>
741 4653 28100 TS16.dat
<BR>
836 4856 30916 TS24.dat
<BR>
846 5839 37442 TS22.dat
<BR>
968 6042 38088 TS13.dat
<BR>
1061 6086 39001 TS20.dat
<BR>
1084 5742 34816 TS27.dat
<BR>
1107 4782 29440 TS21.dat
<BR>
1128 6300 37140 TS03.dat
<BR>
1175 6573 40280 TS05.dat
<BR>
1621 8804 58396 TS17.dat
<BR>
1758 8521 54235 TS23.dat</FONT></TT>
</BLOCKQUOTE>
<P>
You can get summary information about columns with the <TT><FONT FACE="Courier">summ</FONT></TT>
command. For example, to get summary information for the <TT><FONT FACE="Courier">test.data</FONT></TT>
file for averages, use this command:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">summ -m < test.data</FONT></TT>
</BLOCKQUOTE>
<P>
Here's the resulting output:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">Rows: 13<BR>
Min, Avg, Max, Total for LINE: 644, 1050, 1758, 13656<BR>
Min, Avg, Max, Total for WORD: 3966, 5856, 8804, 76136<BR>
Min, Avg, Max, Total for BYTE: 24383, 36669, 58396, 476699<BR>
Min, Avg, Max, Total for NAME: 0, 0, 0, 0</FONT></TT>
</BLOCKQUOTE>
<P>
You can join two tables together on a per-column basis to get
a merged table. The command to do this is <TT><FONT FACE="Courier">jointbl</FONT></TT>.
The <TT><FONT FACE="Courier">-c</FONT></TT> option does the merge
for you on a per-column basis. Consider the two files <TT><FONT FACE="Courier">p1.dat</FONT></TT>
and <TT><FONT FACE="Courier">p2.dat</FONT></TT> with a common
column of <TT><FONT FACE="Courier">NAME</FONT></TT> in each file.
The merged output is shown with this command:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">jointbl -c < p1.dat NAME p2.dat</FONT></TT>
</BLOCKQUOTE>
<P>
The use of the <TT><FONT FACE="Courier">jointbl</FONT></TT> command
is shown in the following input/output example:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">$<B> cat p1.dat<BR>
<BR>
</B>$<BR>
$ <B>cat p2.dat<BR>
</B>#<BR>
# P2<BR>
#<BR>
LINE NAME<BR>
4N 8<BR>
1128 TS03.dat<BR>
644 TS04.dat<BR>
1175 TS05.dat<BR>
968 TS13.dat<BR>
687 TS14.dat<BR>
741 TS16.dat<BR>
1621 TS17.dat<BR>
1061 TS20.dat<BR>
1107 TS21.dat<BR>
846 TS22.dat<BR>
1758 TS23.dat<BR>
836 TS24.dat<BR>
1084 TS27.dat<BR>
$<BR>
$ <B>jointbl -c < p1.dat NAME p2.dat<BR>
</B>#<BR>
# P1<BR>
#<BR>
#<BR>
# P2<BR>
#<BR>
NAME BYTE LINE<BR>
8 5N 4N<BR>
TS03.dat 37140 1128
<BR>
TS04.dat 24462 644
<BR>
TS05.dat 40280 1175
<BR>
TS13.dat 38088 968
<BR>
TS14.dat 24383 687
<BR>
TS16.dat 28100 741
<BR>
TS17.dat 58396 1621
<BR>
TS20.dat 39001 1061
<BR>
TS21.dat 29440 1107
<BR>
TS22.dat 37442
846<BR>
TS23.dat 54235 1758
<BR>
TS24.dat 30916
836<BR>
TS27.dat 34816 1084</FONT></TT>
</BLOCKQUOTE>
<P>
Other more powerful features of this RDB package are listed in
the <TT><FONT FACE="Courier">RDB.ps</FONT></TT> PostScript file.
It prints out to a 72-page manual with examples and details on
all of the commands available for you. If you do not feel like
killing a tree, you can use <TT><FONT FACE="Courier">ghostview</FONT></TT>
to view the file.
<H2><A NAME="Summary"><FONT SIZE=5 COLOR=#FF0000>Summary</FONT></A>
</H2>
<P>
Perl supplies a flat database package in the DBM utilities. The
modules allow Perl scripts to map hashes to disk files for storage.
For most users, storing data with DBM utilities is sufficient.
Some <TT><FONT FACE="Courier">DBD::</FONT></TT> and <TT><FONT FACE="Courier">DBI::</FONT></TT>
modules are available as front-ends to commercial databases such
as Oracle, Sybase, Informix, and Quickbase. You need the specific
database and database engine installed on your machine in order
for the <TT><FONT FACE="Courier">DBD::</FONT></TT> code to work.
The RDB package provides a text file-based relational database
management system. Utilities in the RDB package are a set of Perl
programs that operate on rows and columns of data files.
<P>
<HR WIDTH="100%"></P>
<CENTER><P><A HREF="ch17.htm" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/ch17.htm"><IMG SRC="pc.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/pc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="#CONTENTS"><IMG SRC="cc.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/cc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="index.htm" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/index.htm"><IMG SRC="hb.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/hb.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="ch19.htm" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/ch19.htm"><IMG
SRC="nc.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/nc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A></P></CENTER>
<P>
<HR WIDTH="100%"></P>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -