I could solve it. Able to store in array, sort it, remove duplicates and
print it. Sure there may be better ways to do it, but it seems to
work.  Amazing power of perl in so few lines.

Thanks

Fixed Script below:
 ============
#!/usr/bin/perl -w
#use strict
use File::Find;
my $dir_to_process = "C:/Mydir";
#opendir DH, $dir_to_process or die "Cannot open $dir_to_process:$1";
print "Files in $dir_to_process are:\n";
$i = 0;
my @url_array ;
find (\&wanted, $dir_to_process);
my %hash = map { $_ => 1} @url_array;
my @unique_url_array = keys %hash;
my @sorted_url_array = sort(@unique_url_array);
print "Printing sorted_url_array:\n";
 for ($j=0; $j <= $#sorted_url_array; $j++)
 {
      print ($sorted_url_array[$j], "\n");  # This PRINTS sorted,
non-duplicate array
 }
print "END Printing sorted_url_array\n";
sub wanted {
   return unless -f;        #skip directories
   if ( -f and /.html?/ ) {
      $file = $_;
   open FILE, $file;
      @lines = <FILE>;
      close FILE;
   for $line (@lines) {
      if ($line =~ /somepattern/) {
             $url_line = $';
             $url_line =~ /\"/;
    $url = $`;
   $url_array[$i] = $url;
   $i++;
   }
    }
 }

 if ( -f and /.jsp?/ ) {
      $file = $_;
      open FILE, $file;
      @lines = <FILE>;
      close FILE;
   for $line (@lines) {
      if ($line =~ /somepattern/) {
   $url_line = $';
   $url_line =~ /\"/;
   $url = $`;
   $url_array[$i] = $url;
   $i++;
   }
    }
 }




}

Reply via email to