Perl 1997 Perl As A System Glue

885 views

Published on

This presentation, at the 1st Perl Conference, introduced cross platform perl/unix web development. Of special interest was the examination of what are now called database sockets. This may have been the first presentation of the subject.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
885
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Perl 1997 Perl As A System Glue

  1. 1. Perl As A System Glue Patrick M. Benson University of Washington Information Systems http://weber.u.washington.edu/~pbenson email: pbenson@cac.washington.edu
  2. 2. Overview of Examples <ul><li>File Store-and-Forward </li></ul><ul><li>Introductory Level Example </li></ul><ul><li>Perl CGI </li></ul><ul><li>Intermediate Level Example </li></ul><ul><li>Half-a-Perl Concept </li></ul><ul><li>SQL Development </li></ul>
  3. 3. File Store-and-Forward <ul><li>VAX/VMS with Multinet outside our firewall running FOCUS under DCL </li></ul><ul><li>RS-6000 UNIX/AIX inside our firewall with strict security measures </li></ul><ul><li>IBM-309x/VM with an unknown Comm System on dedicated RJE line through our firewall </li></ul>
  4. 4. File Store-and-Forward
  5. 5. File Store-and-Forward <ul><li>RSH and FTP work because ... </li></ul><ul><li>I trust you enough to let you talk to me, I’ll take data files you say are safe. </li></ul><ul><li>You trust me enough to give me your account / password and to let me send a copy of your data file back to you. </li></ul>
  6. 6. <ul><li>Perl in this process (See Listing 2, RS6000/AIX Perl Script) </li></ul><ul><li>IF Statements, Logical Operators, Code Blocks </li></ul><ul><li>16. if ($#ARGV != 1) { </li></ul><ul><li>17. print “ *******************************************”; </li></ul><ul><li>18. print “ * ARGUMENT MISMATCH ERROR #”, $#ARGV *”; </li></ul><ul><li>19. print “ ******************************************* ”; </li></ul><ul><li>20. exit -1;} </li></ul><ul><li>Arguments, Array Notation, Concatenation, Constants </li></ul><ul><li>23. $infile = $ARGV[0]; </li></ul><ul><li>24. $chkfile = $infile . ‘_check’; </li></ul><ul><li>Back-Tic Execution, Nested Quotes, Imbedded Pipes </li></ul><ul><li>43. $get_file = ‘echo “get $outfile $chkfile” | ftp vsvm.dis.wa.gov‘; </li></ul>File Store-and-Forward
  7. 7. Overview of Examples <ul><li>File Store-and-Forward </li></ul><ul><li>Introductory Level Example </li></ul><ul><li>Perl CGI </li></ul><ul><li>Intermediate Level Example </li></ul><ul><li>Half-a-Perl Concept </li></ul><ul><li>SQL Development </li></ul>
  8. 8. Perl CGI <ul><li>Web Client (PC, Mac, Xterm with Netscape 2.1 or better or similar, marginal HTML 3.0 or better compliant) </li></ul><ul><li>Web Server (Perl 4.2 or better) </li></ul><ul><li>Data Server (Unix Box with Informix, Sybase, Oracle ISQL or similar) </li></ul>
  9. 9. Perl CGI
  10. 10. Perl CGI <ul><li>Content, Cache Control, Libraries, Initialization </li></ul><ul><li>Accept static HTML parameters & Main Driver </li></ul><ul><li>Construct ISQL command to meet request </li></ul><ul><li>Copy the ISQL command through the firewall to a data file </li></ul><ul><li>Pass filename and CAT statements as a parameter to ISQL command file </li></ul><ul><li>Parse returned string into rows </li></ul><ul><li>Build HTML Page </li></ul>
  11. 11. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Content, Cache Control, Libraries, Initialization </li></ul><ul><li>9. print &quot;CONTENT-TYPE: text/html&quot;,&quot; &quot;; </li></ul><ul><li>10. print &quot;Pragma: no-cache&quot;,&quot; &quot;; </li></ul><ul><li>12. require &quot;/www/world/cgi-bin/cgi-lib.pl&quot;; </li></ul><ul><li>14. $rcp_user = ‘oasis’; </li></ul><ul><li>15. $rcp_cmd = ‘/usr/ucb/rcp’; </li></ul><ul><li>16. $rcp_host = ‘equip.u.washington.edu’; </li></ul><ul><li>18. $rsh_user = ‘oasis’; </li></ul><ul><li>19. $rsh_cmd = ‘/usr/ucb/rsh’; </li></ul><ul><li>21. $sql_host = ‘equip.u.washington.edu’; </li></ul><ul><li>22. $sql_db = ‘oasisdev@equipdev’; </li></ul><ul><li>27. $rcp_destination = $rcp_user . ‘@’ . $rcp_host . ‘:.’; </li></ul><ul><li>28. $sql_user = $sql_host . ‘ -l ‘ . $rsh_user . ‘ ‘; </li></ul>
  12. 12. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Accept static HTML parameters & Main Driver </li></ul><ul><li>37. &ReadParse; </li></ul><ul><li>39. $table_name = $in{'table_name'}; </li></ul><ul><li>41. $set_extract; </li></ul><ul><li>42. &run_extract; </li></ul><ul><li>43. &write_report; </li></ul><ul><li>45. exit; </li></ul>
  13. 13. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Construct ISQL command to meet request </li></ul><ul><ul><ul><li>49. sub set_extract { </li></ul></ul></ul><ul><ul><ul><li>53. $sellist = ‘name_value, name_full_text’; </li></ul></ul></ul><ul><ul><ul><li>54. $passlist = “'$table_name'”; </li></ul></ul></ul><ul><ul><ul><li>55. $sql_tables = ‘UNLOAD TO TEMPTBL SELECT ‘ . $sellist </li></ul></ul></ul><ul><ul><ul><li>56. . ‘ FROM names’ </li></ul></ul></ul><ul><ul><ul><li>57. . ‘ WHERE name_type = ‘ . $passlist </li></ul></ul></ul><ul><ul><ul><li>58. . ‘ ’; </li></ul></ul></ul><ul><ul><ul><li>59. } </li></ul></ul></ul>
  14. 14. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Copy the ISQL command through the firewall to a data file </li></ul><ul><ul><ul><li>76. $info_time = `$rsh_cmd $sql_user &quot;/bin/date &quot;`; </li></ul></ul></ul><ul><ul><ul><li>77. if ($info_time eq '') { </li></ul></ul></ul><ul><ul><ul><li>78. print &quot;<P>Database Server not responding ... try again later.&quot;; </li></ul></ul></ul><ul><ul><ul><li>79. exit; </li></ul></ul></ul><ul><ul><ul><li>80. } </li></ul></ul></ul><ul><ul><ul><li>85. $d = `rcp isql_tables.sql $rcp_destination`; </li></ul></ul></ul>
  15. 15. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Pass filename and CAT statements as a parameter to ISQL command file </li></ul><ul><li>94. $info = `rsh $sql_user &quot;$rsh_file $sql_db isql_tables.sql; cat -e -v TEMPTBL ; rm TEMPTBL&quot;`; </li></ul>
  16. 16. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Parse Returned String into Rows </li></ul><ul><li>100. @table_data = split('|$',$info); </li></ul><ul><li>101. $row_count = $#table_data; </li></ul><ul><li>102. @row_data = split('|',$table_data[0]); </li></ul><ul><li>103. $col_count = $#row_data + 1; </li></ul>
  17. 17. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Build HTML Page </li></ul><ul><li>108. sub write_report { </li></ul><ul><li>110 &build_headers; </li></ul><ul><li>111. &write_header; </li></ul><ul><li>112. &write_body </li></ul><ul><li>113 &write_footers; </li></ul><ul><li>114. } </li></ul>
  18. 18. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Build HTML Page - Build Headers </li></ul><ul><li>122. $table_title[0] = ‘Column 1’; </li></ul><ul><li>123. $table_title[1] = ‘Column 2’; </li></ul><ul><li>125. if ($table_name eq “class”) { </li></ul><ul><li>126. $table_title[0] = ‘Class Code’; </li></ul><ul><li>127. $table_title[1] = ‘Class of Equipment’; </li></ul><ul><li>128. elsif ($table_name eq &quot;cond&quot;) { </li></ul><ul><li>129. $table_title[0] = ‘Condition Code’; </li></ul><ul><li>130. $table_title[1] = ‘Asset's Present Condition’;} </li></ul><ul><li>(and so on until all possible table column titles are set) </li></ul><ul><li>140. } </li></ul>
  19. 19. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Build HTML Page - Write Header </li></ul><ul><li>144. sub write_header { </li></ul><ul><li>148. print <<end_of_header; </li></ul><ul><li>149. <HTML> </li></ul><ul><li>150. <HEAD><TITLE> </li></ul><ul><li>151. Table Contents Inquiry </li></ul><ul><li>152. </TITLE></HEAD> </li></ul><ul><li>153. <BODY </li></ul><ul><li>161. end_of_header </li></ul><ul><li>162. } </li></ul>
  20. 20. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Build HTML Page - Write Body - Table Header </li></ul><ul><li>175. print &quot;<P> <TABLE COL=$col_count BORDER=&quot;1&quot; &quot;; </li></ul><ul><li>176. for ($i = 0; $i < $row_count; $i++) { </li></ul><ul><li>180. if ($i == 0) { </li></ul><ul><li>181. print &quot;<THEAD><TR>&quot;; </li></ul><ul><li>182. for ($j = 0; $j < $col_count; $j++) { </li></ul><ul><li>183. print &quot;<TD ALIGN=&quot;CENTER&quot;> $table_title[$j] </TD>&quot;; </li></ul><ul><li>184. } </li></ul><ul><li>185. print &quot;</THEAD><TBODY>&quot;; </li></ul><ul><li>186. } </li></ul>
  21. 21. Perl CGI <ul><li>See Listing 3, Perl CGI </li></ul><ul><li>Build HTML Page - Write Body - Table Rows </li></ul><ul><li>195. @row_data = split('|',$table_data[$i]); </li></ul><ul><li>196. for ($j = 0; $j < $col_count; $j++) { </li></ul><ul><li>197. if ($j == 0) { </li></ul><ul><li>198. $row_data[0] =~ s/xA//g; </li></ul><ul><li>199. print &quot;<TR><TD><FORMMETHOD=&quot;GET&quot;ACTION=&quot;./update_table.cgi&quot;> </li></ul><ul><li>200. <INPUT TYPE=&quot;hidden&quot; NAME=&quot;$table_name&quot; </li></ul><ul><li>201. VALUE=&quot;$row_data[0]&quot;> </li></ul><ul><li>202. <INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;$row_data[0]&quot;></FORM></TD>&quot;; </li></ul><ul><li>203. } else { </li></ul><ul><li>204. print &quot;<TD> $row_data[$j] </TD>&quot;; </li></ul><ul><li>205. } </li></ul><ul><li>206. } </li></ul>
  22. 22. Perl CGI
  23. 23. Perl As A System Glue <ul><li>Pluses </li></ul><ul><li>Cost effective cross platform superglue. </li></ul><ul><li>Efficient and Structured code possible </li></ul><ul><li>1 hour of Perl = 8 hours of COBOL </li></ul><ul><li>Minuses </li></ul><ul><li>10 ways to mess up maintenance staff </li></ul><ul><li>Difficult post-implementation support environment </li></ul><ul><li>All the HTML Bandwagon problems </li></ul>

×