#!usr/bin/perl use strict; use warnings; my $file; my $path = "/mnt/data/Programming/"; my $i = 0; my @regex = qw( file split opendir push sort sub % STDIN); my @lines; my $prev_line; my $curr_line; # This program looks through a directory, reads through each file contained # within, and sorts them based on several different pattern matching criteria, # then sends links to each file containing a match for each keyword, to an index # page. opendir (PRO, "/mnt/data/Programming") || die $!; foreach $file (readdir (PRO)) { open (IN, "$file") || die $!; while () { #print $_; # de-bug print statement 1 push(@lines, $_); #print $lines[31];# de-bug print statement 2 if ($lines[$i] =~ /$regex[$i]/) { if ($i >= 1) { $prev_line = $lines[$i - 1]; } # end if $curr_line = $lines[$i]; open (OUT, ">/mnt/data/Programming/links") || die $!; print OUT " < a HREF=\"$path . $file\">$regex[$i]"; print OUT $file . "\n"; print OUT $prev_line . "\n"; print OUT $curr_line . "\n"; $i++; close(OUT); } # end if } # end while close(IN); } # end foreach #### * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space ?: * zero or more /x ign. wh.space