Slide 5.1: Fundamental file processing demonstrations
Slide 5.3: Entering book information
Home

Fundamental File Processing Demo (Cont.)


Once the button Submit or Help of the top part of the previous interface is clicked, the following CGI Perl script is activated. It performs the following tasks:
  1. Retrieves web input data.
  2. Decides which of the two buttons, Submit and Help, is clicked.
  3. If the button Submit is clicked, decides which of the three tasks is picked.
  4. Displays the appropriate web interface based on the task picked.
  5. If the task Clear books.txt is picked, also deletes the file books.txt by using the Unix command rm .
~wenchen/public_html/cgi-bin/351/week5/FPDemo.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI; 
$query = new CGI;
# Retrieve web argument values.
$act   = $query->param( 'act'  );

if ( $act eq "Submit" ) {
  $select = $query->param( 'select' );
  if ( $select eq "clear" ) {
    system( "rm books.txt;  cat FPDemo.html" );
  }
  elsif ( $select eq "enter" ) {
    system( "cat EnterBooks1.html" );
  }
  elsif ( $select eq "list" ) {
    system( "cat ListBooks.html" );
  }
  else {
    print( "No such option: $select" );
  }
}
elsif ( $act eq "Help" ) {
  system( "/bin/cat Help.html" );
}
else {
  print( "No such option: $act" );
}