⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<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&nbsp;&nbsp;&nbsp;&nbsp;WORD&nbsp;&nbsp;&nbsp;&nbsp;BYTE&nbsp;&nbsp;&nbsp;&nbsp;NAME

<BR>

4N&nbsp;&nbsp;&nbsp;&nbsp;4N&nbsp;&nbsp;&nbsp;&nbsp;5N&nbsp;&nbsp;&nbsp;&nbsp;8

<BR>

1128&nbsp;&nbsp;&nbsp;&nbsp;6300&nbsp;&nbsp;&nbsp;&nbsp;37140&nbsp;&nbsp;&nbsp;&nbsp;TS03.dat

<BR>

&nbsp;644&nbsp;&nbsp;&nbsp;&nbsp;3966&nbsp;&nbsp;&nbsp;&nbsp;24462&nbsp;&nbsp;&nbsp;&nbsp;TS04.dat

<BR>

1175&nbsp;&nbsp;&nbsp;&nbsp;6573&nbsp;&nbsp;&nbsp;&nbsp;40280&nbsp;&nbsp;&nbsp;&nbsp;TS05.dat

<BR>

&nbsp;968&nbsp;&nbsp;&nbsp;&nbsp;6042&nbsp;&nbsp;&nbsp;&nbsp;38088&nbsp;&nbsp;&nbsp;&nbsp;TS13.dat

<BR>

&nbsp;687&nbsp;&nbsp;&nbsp;&nbsp;3972&nbsp;&nbsp;&nbsp;&nbsp;24383&nbsp;&nbsp;&nbsp;&nbsp;TS14.dat

<BR>

&nbsp;741&nbsp;&nbsp;&nbsp;&nbsp;4653&nbsp;&nbsp;&nbsp;&nbsp;28100&nbsp;&nbsp;&nbsp;&nbsp;TS16.dat

<BR>

1621&nbsp;&nbsp;&nbsp;&nbsp;8804&nbsp;&nbsp;&nbsp;&nbsp;58396&nbsp;&nbsp;&nbsp;&nbsp;TS17.dat

<BR>

1061&nbsp;&nbsp;&nbsp;&nbsp;6086&nbsp;&nbsp;&nbsp;&nbsp;39001&nbsp;&nbsp;&nbsp;&nbsp;TS20.dat

<BR>

1107&nbsp;&nbsp;&nbsp;&nbsp;4782&nbsp;&nbsp;&nbsp;&nbsp;29440&nbsp;&nbsp;&nbsp;&nbsp;TS21.dat

<BR>

&nbsp;846&nbsp;&nbsp;&nbsp;&nbsp;5839&nbsp;&nbsp;&nbsp;&nbsp;37442&nbsp;&nbsp;&nbsp;&nbsp;TS22.dat

<BR>

1758&nbsp;&nbsp;&nbsp;&nbsp;8521&nbsp;&nbsp;&nbsp;&nbsp;54235&nbsp;&nbsp;&nbsp;&nbsp;TS23.dat

<BR>

&nbsp;836&nbsp;&nbsp;&nbsp;&nbsp;4856&nbsp;&nbsp;&nbsp;&nbsp;30916&nbsp;&nbsp;&nbsp;&nbsp;TS24.dat

<BR>

1084&nbsp;&nbsp;&nbsp;&nbsp;5742&nbsp;&nbsp;&nbsp;&nbsp;34816&nbsp;&nbsp;&nbsp;&nbsp;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 &lt; test.data  LINE &gt; 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&nbsp;&nbsp;&nbsp;&nbsp;WORD&nbsp;&nbsp;&nbsp;&nbsp;BYTE&nbsp;&nbsp;&nbsp;&nbsp;NAME

<BR>

4N&nbsp;&nbsp;&nbsp;&nbsp;4N&nbsp;&nbsp;&nbsp;&nbsp;5N&nbsp;&nbsp;&nbsp;&nbsp;8

<BR>

&nbsp;644&nbsp;&nbsp;&nbsp;&nbsp;3966&nbsp;&nbsp;&nbsp;&nbsp;24462&nbsp;&nbsp;&nbsp;&nbsp;TS04.dat

<BR>

&nbsp;687&nbsp;&nbsp;&nbsp;&nbsp;3972&nbsp;&nbsp;&nbsp;&nbsp;24383&nbsp;&nbsp;&nbsp;&nbsp;TS14.dat

<BR>

&nbsp;741&nbsp;&nbsp;&nbsp;&nbsp;4653&nbsp;&nbsp;&nbsp;&nbsp;28100&nbsp;&nbsp;&nbsp;&nbsp;TS16.dat

<BR>

&nbsp;836&nbsp;&nbsp;&nbsp;&nbsp;4856&nbsp;&nbsp;&nbsp;&nbsp;30916&nbsp;&nbsp;&nbsp;&nbsp;TS24.dat

<BR>

&nbsp;846&nbsp;&nbsp;&nbsp;&nbsp;5839&nbsp;&nbsp;&nbsp;&nbsp;37442&nbsp;&nbsp;&nbsp;&nbsp;TS22.dat

<BR>

&nbsp;968&nbsp;&nbsp;&nbsp;&nbsp;6042&nbsp;&nbsp;&nbsp;&nbsp;38088&nbsp;&nbsp;&nbsp;&nbsp;TS13.dat

<BR>

1061&nbsp;&nbsp;&nbsp;&nbsp;6086&nbsp;&nbsp;&nbsp;&nbsp;39001&nbsp;&nbsp;&nbsp;&nbsp;TS20.dat

<BR>

1084&nbsp;&nbsp;&nbsp;&nbsp;5742&nbsp;&nbsp;&nbsp;&nbsp;34816&nbsp;&nbsp;&nbsp;&nbsp;TS27.dat

<BR>

1107&nbsp;&nbsp;&nbsp;&nbsp;4782&nbsp;&nbsp;&nbsp;&nbsp;29440&nbsp;&nbsp;&nbsp;&nbsp;TS21.dat

<BR>

1128&nbsp;&nbsp;&nbsp;&nbsp;6300&nbsp;&nbsp;&nbsp;&nbsp;37140&nbsp;&nbsp;&nbsp;&nbsp;TS03.dat

<BR>

1175&nbsp;&nbsp;&nbsp;&nbsp;6573&nbsp;&nbsp;&nbsp;&nbsp;40280&nbsp;&nbsp;&nbsp;&nbsp;TS05.dat

<BR>

1621&nbsp;&nbsp;&nbsp;&nbsp;8804&nbsp;&nbsp;&nbsp;&nbsp;58396&nbsp;&nbsp;&nbsp;&nbsp;TS17.dat

<BR>

1758&nbsp;&nbsp;&nbsp;&nbsp;8521&nbsp;&nbsp;&nbsp;&nbsp;54235&nbsp;&nbsp;&nbsp;&nbsp;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 &lt; 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 &lt; 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&nbsp;&nbsp;&nbsp;&nbsp;NAME<BR>

4N&nbsp;&nbsp;&nbsp;&nbsp;8<BR>

1128&nbsp;&nbsp;&nbsp;&nbsp;TS03.dat<BR>

&nbsp;644&nbsp;&nbsp;&nbsp;&nbsp;TS04.dat<BR>

1175&nbsp;&nbsp;&nbsp;&nbsp;TS05.dat<BR>

&nbsp;968&nbsp;&nbsp;&nbsp;&nbsp;TS13.dat<BR>

&nbsp;687&nbsp;&nbsp;&nbsp;&nbsp;TS14.dat<BR>

&nbsp;741&nbsp;&nbsp;&nbsp;&nbsp;TS16.dat<BR>

1621&nbsp;&nbsp;&nbsp;&nbsp;TS17.dat<BR>

1061&nbsp;&nbsp;&nbsp;&nbsp;TS20.dat<BR>

1107&nbsp;&nbsp;&nbsp;&nbsp;TS21.dat<BR>

&nbsp;846&nbsp;&nbsp;&nbsp;&nbsp;TS22.dat<BR>

1758&nbsp;&nbsp;&nbsp;&nbsp;TS23.dat<BR>

&nbsp;836&nbsp;&nbsp;&nbsp;&nbsp;TS24.dat<BR>

1084&nbsp;&nbsp;&nbsp;&nbsp;TS27.dat<BR>

$<BR>

$ <B>jointbl -c &lt; p1.dat NAME p2.dat<BR>

</B>#<BR>

# P1<BR>

#<BR>

#<BR>

# P2<BR>

#<BR>

NAME&nbsp;&nbsp;&nbsp;&nbsp;BYTE&nbsp;&nbsp;&nbsp;&nbsp;LINE<BR>

8&nbsp;&nbsp;&nbsp;&nbsp;5N&nbsp;&nbsp;&nbsp;&nbsp;4N<BR>

TS03.dat&nbsp;&nbsp;&nbsp;&nbsp;37140&nbsp;&nbsp;&nbsp;&nbsp;1128

<BR>

TS04.dat&nbsp;&nbsp;&nbsp;&nbsp;24462&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;644

<BR>

TS05.dat&nbsp;&nbsp;&nbsp;&nbsp;40280&nbsp;&nbsp;&nbsp;&nbsp;1175

<BR>

TS13.dat&nbsp;&nbsp;&nbsp;&nbsp;38088&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;968

<BR>

TS14.dat&nbsp;&nbsp;&nbsp;&nbsp;24383&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;687

<BR>

TS16.dat&nbsp;&nbsp;&nbsp;&nbsp;28100&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;741

<BR>

TS17.dat&nbsp;&nbsp;&nbsp;&nbsp;58396&nbsp;&nbsp;&nbsp;&nbsp;1621

<BR>

TS20.dat&nbsp;&nbsp;&nbsp;&nbsp;39001&nbsp;&nbsp;&nbsp;&nbsp;1061

<BR>

TS21.dat&nbsp;&nbsp;&nbsp;&nbsp;29440&nbsp;&nbsp;&nbsp;&nbsp;1107

<BR>

TS22.dat&nbsp;&nbsp;&nbsp;&nbsp;37442&nbsp;&nbsp;&nbsp;&nbsp;

846<BR>

TS23.dat&nbsp;&nbsp;&nbsp;&nbsp;54235&nbsp;&nbsp;&nbsp;&nbsp;1758

<BR>

TS24.dat&nbsp;&nbsp;&nbsp;&nbsp;30916&nbsp;&nbsp;&nbsp;&nbsp;

836<BR>

TS27.dat&nbsp;&nbsp;&nbsp;&nbsp;34816&nbsp;&nbsp;&nbsp;&nbsp;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 + -