in reply to Need help with comparison code
- Miller#!/usr/bin/perl use strict; use warnings; # emailsent.txt-will contain the name of all files for whom an alert h +as been sent # emailtogo.txt-will contain the name of all new files for whom an ale +rt has to be sent my $matchfile = 'emailsent.txt'; my $outfile = 'emailtogo.txt'; ########################## my $directory = 'C:\'; opendir(DIR, $directory); my @files = grep { $_ ne '.' && $_ ne '..' } readdir DIR; closedir(DIR); # storing all file names in the folder in an array foreach(@files){ print $_,"\n"; } # Build list of old files for comparison open my $ih, '<', $matchfile or die "Can't open file, $matchfile: $!"; my %oldFiles = map {chomp; $_ => 1} <$ih>; close $ih; # Append new files to total list open my $oh_tot, '>>', $matchfile or die "Can't open file, $matchfile: + $!"; open my $oh_new, '>', $outfile or die "Can't open file, $outfile: $!"; # Comparing the array to the names in $matchfile foreach my $file (@files) { if (! $oldFiles{$file}) { print $oh_tot "$file\n"; print $oh_new "$file\n"; } } close $oh_tot; close $oh_new;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need help with comparison code
by sowais (Sexton) on Feb 04, 2011 at 20:29 UTC | |
by wind (Priest) on Feb 04, 2011 at 22:41 UTC |