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

Perl 1997 Perl As A System Glue

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