Database Reference
In-Depth Information
• For import into existing tables, the labels help you match datafile columns with the
table columns if they are not necessarily in the same order.
• The labels can be used for column names when creating a new table automatically
or semiautomatically from a datafile. For example, Recipe 11.11 discusses a utility
that examines a datafile and guesses the CREATE TABLE statement to use to create a
table from the file. If a label row is present, the utility uses the labels for column
names.
Tab-Delimited, Linefeed-Terminated Format
Although datafiles may be written in many formats, it's unwieldy to include machinery
for reading multiple formats within each file-processing utility you write. For that rea‐
son, many of the utilities described in this chapter assume for simplicity that their input
is in tab-delimited, linefeed-terminated format. (This is also the default format for
MySQL's LOAD DATA statement.) By making this assumption, it becomes easier to write
programs that read files.
On the other hand, something has to be able to read data in other formats. To handle
that problem, we'll develop a cvt_file.pl script that can read several types of files (see
Recipe 11.6 ). The script is based on the Perl Text::CSV_XS module, which despite its
name is useful for much more than just CSV data. cvt_file.pl can convert between many
file types, making it possible for other programs that require tab-delimited lines to be
used with files not originally written in that format. In other words, you can use cvt_file.pl
to convert a file to tab-delimited, linefeed-terminated format, and then any program
that expects that format can process the file.
Notes on Invoking Shell Commands
This chapter shows a number of programs that you invoke from the command line
using a shell like bash or tcsh under Unix or cmd.exe (“the command prompt”) under
Windows. Many of the example commands for these programs use quotes around op‐
tion values, and sometimes an option value is itself a quote character. Quoting conven‐
tions vary from one shell to another, but the following rules seem to work with most of
them (including cmd.exe under Windows):
• For an argument that contains spaces, enclose it within double quotes to prevent
the shell from interpreting it as multiple separate arguments. The shell strips the
quotes and passes the argument to the command intact.
• To include a double-quote character in the argument itself, precede it with a
backslash.
 
Search WWH ::




Custom Search