The code in these examples takes advantage of the fact that hash keys are unique. We create a key using the tiff filename or the pdf filename, and increment the hash's value. If the value of the hash is 2, that means there was a pdf and a matching tiff. If it equals 1, then there was only one pdf or one tiff.
You can also figure out if there is a tiff without a pdf, and don't care if there is a pdf without a tiff. One way to do so is: foreach (readdir(DIR)) { next unless /pdf$/ or /tiff$/ or /tif$/; if ($_ =~ /^(.+).tif$/i || $_ =~ /^(.+).tiff$/i) { ++$exists{$1}; } elsif ($_ =~ /^(.+).pdf$/i) { $exists{$1} += 2; } else { die("Major malfuntion on '$_'\n"); } } closedir DIR; # Assuming each filename pair is unique: # $exists{$_} == 1; # One tiff # $exists{$_} == 2; # One pdf # $exists{$_} == 3; # One tiff and one pdf print join('\n', grep { $exists{$_} == 1 } keys %exists), "\n"; __END__ =-= Robert Thompson On Wed, Jul 10, 2002 at 11:19:04AM -0400, Chas Owens wrote: > On Wed, 2002-07-10 at 10:17, Rupert Heesom wrote: > > I'm working with directories in which there should be a number of graphs > > files; one TIFF file, one PDF file. > > > > I'm wanting to find which TIFF files there is no corresponding PDF file for. > > > > One way to do this is to create 2 lists (arrays), one for all the TIFF files > > in a directory, the other list for all the PDF files in the same directory. > > Then to compare the 2 lists to find the missing PDF files. > > > > However, if there is a better way to do this (I'm new to Perl), can anyone > > let me know? > > > > If there _is_ no better way, what's some good perl code for a Win32 script? > > > > Regs > > Rupert Heesom > > Asst Distribution Engineer > > Adventist World Radio > > Hmmm... My first thought is: > > > #!/usr/bin/perl > > use strict; > > my %exists; > > opendir DIR, $ARGV[0] or die "Horrible death:$!"; > > foreach (readdir(DIR) { > next unless /pdf$/ or /tiff$/ or /tif$/; > (my $file = $_) =~ s/\.(pdf|tiff|tif)$//; #remove the extension > $exists{$file}++; > } > > closedir DIR; > > #print every base filename that only has one occurrence in $path > print join('\n', grep { $exists{$_} == 1 } keys %exists), "\n"; > > > -- > Today is Sweetmorn the 45th day of Confusion in the YOLD 3168 > Pzat! > > Missile Address: 33:48:3.521N 84:23:34.786W > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]