home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Javascript / InteractiveWebDesignJavascript / Scripting / cgi1 / perl / cgi-bin / strip.pl < prev    next >
Encoding:
Perl Script  |  2001-07-18  |  1.2 KB  |  62 lines

  1. #!C:/perl/bin/perl
  2.  
  3. # strip.pl
  4. ######################################
  5. # Strip out un necessary text in 
  6. # periodical file & fake an ISBN #
  7. #
  8. $file = "periodicals.txt";
  9. $tempfile = "CARL-index.txt";
  10.  
  11. sub isbn 
  12. {
  13.     local ($num) = @_;
  14.  
  15.     while (length($num) < 10) {
  16.     $num += int(rand 9999999999);
  17.     }
  18.     return $num;
  19. }
  20.  
  21. open (DAT, "< $file") || die "Can't open $file:$!";
  22. open (TMP, "> $tempfile") || die "Can't open $tempfile:$!";
  23.  
  24. $flg = 0;
  25.  
  26. while (<DAT>) {
  27.  
  28.     if (($_ =~ /^\#/) || ($_ =~ /^--/) || ($_ =~ /^\s\s/)) 
  29.     {
  30.     print TMP $_;
  31.     next;
  32.     } 
  33.     if ($_ =~ /Read more about this title/) {next;}
  34.     if ($_ =~ s/(\d+)(\.)(\s*)([^\~]*)(\~)(.*)/$4/) 
  35.     {
  36.     $num = $1;
  37.     $isbn = &isbn($num);
  38.     $line = $_;
  39.     chomp($line);
  40.     $flg = 1; 
  41.     next;
  42.     }
  43.     if ($flg) {
  44.     if ($_ =~ /([^\/]*)(\/)([^\d]*)(\d*)/) {
  45.         $author = $1; 
  46.         $year = $4;
  47.     }
  48.     }
  49.     if ($flg) {
  50.     if ($_ =~ /(Our Price)([^\$]*)(\$)([^\s]*)/) {
  51.         $price=$4;
  52.         $flg = 0;
  53.         $line .= " Author: " . $author . " Published: " . $year;
  54.         $line .= " ISBN: " . $isbn . " Price: " . $price;
  55.         print TMP "$line\n\n";
  56.     }
  57.     }
  58. }
  59. close (TMP);
  60. close (DAT);
  61. print "done!\n";
  62.