I was recently given the task of combing through 16,000 + files looking for those that were created by one employee. The only flag (since this is a Win95 peer/peer network we're talking about)(yeah, I know, but it pays the rent . . .:-), is the employee number buried in the file. The file is delimited by the character "³" (\xB3). The employee number in this case is 400. Here's the code I used:
#!/usr/bin/perl -w
{
$bucket = 0;
$count = 1;
open (LOGFILE, ">>log.txt") || die "Can't open file: $!";
while ($infile = glob("/biz/employee/data/*")) {
open (INFILE, $infile) || die "Can't open file: $!";
while (<INFILE>) {
print "$count : ";
if ($_ =~ /³400³/) {
$bucket++;
print "Found Employee $bucket times.\n";
print LOGFILE ("$_\n");
}
else { print "\n"; }
$count++;
}
}
print "Finished. Found Employee $bucket time in $count files. \n";
}
I know it's more of a "mundane use for Perl", but it was my first truly fuctional Perl script, and using it I was able to hand my boss the list he wanted in a day instead of longer. As far as I'm concerned, that's cool.
Simplicus.