Slide 5.6: Listing book information
Slide 5.8: A stream file
Home

Listing Book Information (Cont.)


Once the button List or Help of the top part of the previous interface is clicked, the CGI Perl script below will be activated. It mainly performs the following two tasks:
~wenchen/public_html/cgi-bin/351/week5/ListBooks.pl
#!/usr/bin/perl 
use CGI; 
$query = new CGI; 
$act   = $query->param( 'act' ); 
 
if ( $act eq "List" ) { 
  $select = $query->param( 'select' ); 
  if ( $select eq "all" ) {
    print ( "Content-type: text/plain\n\n\n\n\n" );
    system( "sort  books.txt" )
  }
  elsif ( $select eq "one" ) {
    $ISBN = $query->param( 'ISBN' ); 
    # Remove the white spaces before and after the ISBN.
    $ISBN =~ s/^\s*(.*?)\s*$/$1/g;
    $_ = $ISBN;
    if ( /\w{10}/ || /\w{11}/ || /\w{12}/ || /\w{13}/ || /\w{14}/ || /\w{15}/ ) {
      print ( "Content-type: text/plain\n\n\n\n\n" );
      system( "grep  $ISBN  books.txt" );
    }
    else {
      print( "Content-type: text/html\n\n" );
      print( "Wrong ISBN: $ISBN" );
    }
  }
  else {
    print( "Content-type: text/html\n\n" );
    print( "No such option: $select" );
  }
}
elsif ( $act eq "Help" ) {
  print ( "Content-type: text/html\n\n" );
  system( "/bin/cat Help.html" );
}
elsif ( $act eq "Home" ) {
  print ( "Content-type: text/html\n\n" );
  system( "/bin/cat FPDemo.html" );
}
else {
  print( "Content-type: text/html\n\n" );
  print( "No such option: $act" );
}