📄 ch08.htm
字号:
ABC'S OF DECISION MAKING
F0C6-0001.00
Film
Creative Media, 1975
1 Reel. 16mm. Sound. Color. 30 min.
Making a decision is often an unpleasant task. The aspects of decision making to
insure that they will be effective are covered in this film.
A leader's guide is included.
.
College
Adult
ALL SUCCESSFUL PEOPLE HAVE IT
F0C6-0002.00
Film
Motivational Institute, 1980
1 Reel. 16mm. Sound. Color. 28 min.
Narrated by Marilyn Van Derbur, this film helps teens and adults be "somebody"
in their own eyes. It shows how to accomplish something to be proud of -
self-confidence and a positive self-image. It stresses the importance of having
a goal and a logical, well-organized plan to carry it out.
Rated high by 4-H youth
who previewed it.
.
Junior High, grades 7-9
Senior High, grades 10-12
College
Adult
</FONT></PRE>
<PRE><FONT COLOR="#0066FF"></FONT></PRE>
<CENTER>
<H4><A NAME="Heading7"></A><FONT COLOR="#000077">Importing Data into a Database with
DBI</FONT></H4>
</CENTER>
<P>Listing 8.2 uses DBI to import the raw data contained in Listing 8.1 into an mSQL
database. The mSQL databases that are available (such as AV_LIBRARY, in this example)
are managed by MiniSQL, a database manager running on the server. There are five
main steps required to add the records in Listing 8.1 to the database.
<OL>
<LI>line 11 The name of the file containing the raw formatted data is read as an
argument, and a new filehandle is created.
<P>
<LI>line 12 The driver (DBD) for mSQL is installed.
<P>
<LI>line 13 DBI is instructed to connect to the database named AV_LIBRARY.
<P>
<LI>line 93 The dbh IMPORT function of DBI is used to place the data into the database.
<P>
<LI>line 96 Finally, the database connection is closed.
</OL>
<CENTER>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">Listing 8.2. Program that imports
data into an mSQL database</FONT></H3>
</CENTER>
<PRE><FONT COLOR="#0066FF">1: #!/usr/local/bin/perl
2: #
3: # Load the catalog table in the AV_LIBRARY database
4: #
5: # by Tom White
6: #
7: # $Id: load_av.pl,v 1.3 1996/08/27 22:10:36 avlibrar Exp avlibrar $
8:
9: use DBI;
10:
11: open (STDIN, "<$ARGV[0]") || die "Could not open file: $!";
12: $drh = DBI->install_driver( `mSQL' ) || die "Could not install: $DBI::errstr";
13: $dbh = $drh->connect( ``, `AV_LIBRARY' )
14: || die "Could not connect: $DBI::errstr";
15: $dbh->do( `drop table catalog' );
16: $dbh->do(
17: `create table catalog (
18: call_num char(12) primary key,
19: title char(80) not null,
20: subtitle char(80),
21: type char(5) not null,
22: description char(50) not null,
23: publisher char(60) not null,
24: narrative char(1000),
25: #Audience flags: NULL means no; 1, yes.
26: kinder char(1),
27: primer char(1),
28: element char(1),
29: junior char(1),
30: senior char(1),
31: college char(1),
32: adult char(1)
33: )'
34: ) || die "Could not create table: $DBI::errstr";
35:
36: while (! eof STDIN) {
37: # build a record from the input text file
38: $x = &nextline;
39: next unless $x;
40: print "Not ALLCAPS at $lnum\n" if ($x =~ m/[a-z]/);
41: $r{`title'} = $x;
42: $count++;
43: $r{`subtitle'} = &nextline;
44: $r{`call_num'} = &nextline;
45: $r{`type'} = &nextline;
46: $r{`publisher'} = &nextline;
47: $r{`description'} = &nextline;
48: $r{`narrative'} = ``;
49: $x = &nextline;
50: while ( $x ne `.' ) {
51: $r{`narrative'} = $r{`narrative'} . ` ` . $x;
52: $x = &nextline;
53: }
54: $r{`kinder'} = $r{`primer'} = $r{`element'} = $r{`junior'}
55: = $r{`senior'} = $r{`college'} = $r{`adult'} = 0;
56: $x = &nextline;
57: while ($x) {
58: if ($x eq `Kindergarten, ages 3-5') {
59: $r{`kinder'} = 1;
60: } elsif ($x eq `Primary, grades 1-3') {
61: $r{`primer'} = 1;
62: } elsif ($x eq `Elementary, grades 4-6') {
63: $r{`element'} = 1;
64: } elsif ($x eq `Junior High, grades 7-9') {
65: $r{`junior'} = 1;
66: } elsif ($x eq `Senior High, grades 10-12') {
67: $r{`senior'} = 1;
68: } elsif ($x eq `College') {
69: $r{`college'} = 1;
70: } elsif ($x eq `Adult') {
71: $r{`adult'} = 1;
72: }
73: $x = &nextline;
74: }
75: # now build strings for the INSERT
76: $ks = ""; $vs = "";
77: foreach $k (keys %r) {
78: $v = $r{$k};
79: $v =~ s/\\/\\\\/g; #escape backslash
80: $v =~ s/'/\\'/g; #escape single quote
81: if ($v) {
82: $ks = $ks . " $k,";
83: $vs = $vs . " \'$v\',";
84: }
85: # keep up with maximum field lengths
86: $l = length $r{$k};
87: if ( $l > $max{$k} ) {
88: $max{$k} = $l;
89: $ex{$k} = $r{$k};
90: }
91: }
92: chop $ks; chop $vs;
93: $dbh->do( "INSERT INTO catalog ( $ks ) VALUES ( $vs )" )
94: || die "Line $.:Could not add row $DBI::errstr\n";
95: }
96: $dbh->disconnect || die "Could not disconnect: $DBI::errstr";
97: foreach $k (sort keys %max) {
98: printf "%-12s %4d :%s:\n", $k, $max{$k}, $ex{$k};
99: }
100: print "\nFound $count records\n";
101: exit;
102: sub nextline {
103: my $line;
104: $lnum++;
105: $line = <STDIN>;
106: $line =~ s/\s+$//;
107: return $line;
108: }
</FONT></PRE>
<CENTER>
<H4><A NAME="Heading10"></A><FONT COLOR="#000077">Create an HTML Index from a Database</FONT></H4>
</CENTER>
<P>Listing 8.3 uses DBI to query the database and extract the call_num, title, and
subtitle fields. As it extracts the data from the database, the fields are embedded
into HTML to create an index of all titles currently in the A/V library. Figure 8.1
shows the HTML output generated by this program. There are four main steps in the
program in Listing 8.3.
<OL>
<LI>line 11 The driver (DBD) for mSQL is installed.
<P>
<LI>line 12 DBI is instructed to connect to the database named AV_LIBRARY.
<P>
<LI>line 14 After you connect to the database, a prepare function must be invoked
to set up return values before the execute statement is invoked.
<P>
<LI>line 17 The execute statement pulls the values out of the database, and in this
example embeds them in an HTML list.
</OL>
<CENTER>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">Listing 8.3. Program that writes
HTML from the database</FONT></H3>
</CENTER>
<PRE><FONT COLOR="#0066FF">1: #!/usr/local/bin/perl
2: #
3: # Build catalog.html from the catalog table in the AV_LIBRARY database
4: #
5: # by Tom White
6: #
7: # $Id: build_ful.pl,v 1.2 1996/08/28 13:39:51 avlibrar Exp avlibrar $
8: use DBI;
9: $target = "/home1/ces/avlibrar/public_html/catalog.html";
10: open (NEWF,">$target.new") || die "Could not open $target: $!";
11: $drh = DBI->install_driver( `mSQL' ) || die "Could not install: $DBI::errstr";
12: $dbh = $drh->connect( ``, `AV_LIBRARY' )
13: || die "Could not connect: $DBI::errstr";
14: $sth = $dbh->prepare( "SELECT call_num, title, subtitle FROM catalog" )
15: || die "Could not start select: $DBI::errstr";
16: &header;
17: $sth->execute || die "Could not select: $DBI::errstr";
18: while ( ($call_num, $title, $subtitle) = $sth->fetchrow ) {
19: print NEWF qq! <li><tt><a href="display.cgi?cn=$call_num">$call_num</a></tt>
20: $title\n!;
21: if ( $subtitle ) {
22: print NEWF " $subtitle\n";
23: }
24: }
25: $sth->finish || die "Could not finish select: $DBI::errstr";
26: &footer;
27: # $dbh->disconnect || die "Disconnect failed: $DBI::errstr";
28: close NEWF;
29: rename "$target.new", $target || die "Could not rename: $!";
30: exit;
31: sub header {
32: print NEWF <<EOD;
33: <HTML>
34: <HEAD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -