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

📄 ch08.htm

📁 Web_Programming_with_Perl5,一个不错的Perl语言教程。
💻 HTM
📖 第 1 页 / 共 4 页
字号:




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, &quot;&lt;$ARGV[0]&quot;) || die &quot;Could not open file: $!&quot;;



12: $drh = DBI-&gt;install_driver( `mSQL' ) || die &quot;Could not install: $DBI::errstr&quot;;



13: $dbh = $drh-&gt;connect( ``, `AV_LIBRARY' )



14:           || die &quot;Could not connect: $DBI::errstr&quot;;



15:  $dbh-&gt;do( `drop table catalog' );



16:  $dbh-&gt;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 &quot;Could not create table: $DBI::errstr&quot;;



35:



36:  while (! eof STDIN) {



37:    # build a record from the input text file



38:    $x = &amp;nextline;



39:    next unless $x;



40:    print &quot;Not ALLCAPS at $lnum\n&quot; if ($x =~ m/[a-z]/);



41:    $r{`title'} = $x;



42:    $count++;



43:    $r{`subtitle'} = &amp;nextline;



44:    $r{`call_num'} = &amp;nextline;



45:    $r{`type'} = &amp;nextline;



46:    $r{`publisher'} = &amp;nextline;



47:    $r{`description'} = &amp;nextline;



48:    $r{`narrative'} = ``;



49:    $x = &amp;nextline;



50:    while ( $x ne `.' ) {



51:      $r{`narrative'} = $r{`narrative'} . ` ` . $x;



52:      $x = &amp;nextline;



53:    }



54:    $r{`kinder'} = $r{`primer'} = $r{`element'} = $r{`junior'}



55:      = $r{`senior'} = $r{`college'} = $r{`adult'} = 0;



56:    $x = &amp;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 = &amp;nextline;



74:    }



75:    # now build strings for the INSERT



76:    $ks = &quot;&quot;; $vs = &quot;&quot;;



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 . &quot; $k,&quot;;



83:        $vs = $vs . &quot; \'$v\',&quot;;



84:      }



85:      # keep up with maximum field lengths



86:      $l = length $r{$k};



87:      if ( $l &gt; $max{$k} ) {



88:        $max{$k} = $l;



89:        $ex{$k}  = $r{$k};



90:      }



91:    }



92:    chop $ks; chop $vs;



93:    $dbh-&gt;do( &quot;INSERT INTO catalog ( $ks  ) VALUES ( $vs )&quot; )



94:       || die &quot;Line $.:Could not add row $DBI::errstr\n&quot;;



95:  }







96:  $dbh-&gt;disconnect || die &quot;Could not disconnect: $DBI::errstr&quot;;







97:  foreach $k (sort keys %max) {



98:    printf &quot;%-12s %4d :%s:\n&quot;, $k, $max{$k}, $ex{$k};



99:  }







100: print &quot;\nFound $count records\n&quot;;







101: exit;







102: sub nextline {



103:   my $line;



104:   $lnum++;



105:   $line = &lt;STDIN&gt;;



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 = &quot;/home1/ces/avlibrar/public_html/catalog.html&quot;;



10:  open (NEWF,&quot;&gt;$target.new&quot;) || die &quot;Could not open $target: $!&quot;;







11:  $drh = DBI-&gt;install_driver( `mSQL' ) || die &quot;Could not install: $DBI::errstr&quot;;



12:  $dbh = $drh-&gt;connect( ``, `AV_LIBRARY' )



13:            || die &quot;Could not connect: $DBI::errstr&quot;;







14:  $sth = $dbh-&gt;prepare( &quot;SELECT call_num, title, subtitle FROM catalog&quot; )



15:            || die &quot;Could not start select: $DBI::errstr&quot;;







16:  &amp;header;







17:  $sth-&gt;execute || die &quot;Could not select: $DBI::errstr&quot;;



18:  while ( ($call_num, $title, $subtitle) = $sth-&gt;fetchrow ) {



19:    print NEWF qq!  &lt;li&gt;&lt;tt&gt;&lt;a href=&quot;display.cgi?cn=$call_num&quot;&gt;$call_num&lt;/a&gt;&lt;/tt&gt;



20:             $title\n!;



21:    if ( $subtitle ) {



22:      print NEWF &quot; $subtitle\n&quot;;



23:    }



24:  }



25:  $sth-&gt;finish || die &quot;Could not finish select: $DBI::errstr&quot;;







26:  &amp;footer;











27:  # $dbh-&gt;disconnect || die &quot;Disconnect failed: $DBI::errstr&quot;;







28:  close NEWF;



29:  rename &quot;$target.new&quot;, $target || die &quot;Could not rename: $!&quot;;







30:  exit;







31:  sub header {



32:    print NEWF &lt;&lt;EOD;



33:  &lt;HTML&gt;







34:  &lt;HEAD&gt;



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -