Guest User

Process drofa files

a guest
Nov 7th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.02 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. die "Usage: $0 <path to obj dir> <output index file>\n" unless scalar @ARGV == 2;
  7.  
  8. my $path_to_obj = shift;
  9. my $path_to_out = shift;
  10.  
  11. opendir(my $obj_dh, $path_to_obj) || die "Can't open $path_to_obj directory\n";
  12. die "Can't open file $path_to_out\n" unless open(OUT_INDEX, ">$path_to_out");
  13. my @files = readdir($obj_dh);
  14.  
  15. foreach my $file_name (@files)
  16. {
  17.     next if ($file_name eq "." || $file_name eq "..");
  18.     my $file_path = $path_to_obj . "/" . $file_name;
  19.     my $path_to_index = $file_path . "/index.htm";
  20.     my $path_to_index_without_obj = "./" . $file_name . "/index.htm";
  21.     next unless (-d $file_path);
  22.    
  23.     next unless open(INDEX_HTM, $path_to_index);
  24.  
  25.     while (my $line = <INDEX_HTM>)
  26.     {
  27.         if ($line =~ /<title>(.+)<\/title>/)
  28.         {
  29.             my $title = $1;
  30.             print OUT_INDEX "<a href=\"$path_to_index_without_obj\">$title</a><br>\n";
  31.         }
  32.     }
  33.  
  34.     close(INDEX_HTM);
  35. }
  36.  
  37. close($obj_dh);
  38. close(OUT_INDEX);
Advertisement
Add Comment
Please, Sign In to add comment