amelinda has asked for the wisdom of the Perl Monks concerning the following question:
As far as I can tell, the following code should work, but the numbers it reports don't match up. Any idea what's going on?
The current output is:
33600 images in photos (8321 unique). 6571 numbers in numbers_only.txt. 5999 numbers slated for deletion.
#!/usr/bin/perl -w use strict; my $num_file = "numbers_only.txt"; my %currentlist; my $i = 0; open(CURRFILE, "<$num_file") or die "couldn't open the num file: $!\n" +; while (<CURRFILE>) { chomp; $currentlist{$_}++; $i++; } close CURRFILE; my $dir = "images/photos"; opendir FILEDIR, $dir or die "Couldn't open $dir: $!\n"; my @filelist = grep !/^\.\.?$/, readdir FILEDIR; closedir FILEDIR; my %uniquelist; my %deletelist; my $h = 0; foreach my $pic (@filelist) { next unless ($pic =~ /jpg$/); $pic =~ s/^(\d+).*/$1/; $h++; $uniquelist{$pic}++; next if ($currentlist{$pic}); $deletelist{$pic}++; } my $output = "delete_list.txt"; open OUT, ">$output" or die "Couldn't open output: $!\n"; my $j = 0; foreach my $del (sort keys %deletelist) { print OUT "$del\n"; $j++; } close OUT; my $k = 0 + keys %uniquelist; print "$h images in photos ($k unique). $i numbers in numbers_only.txt +. $j numbers slated for deletion.\n"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Build a list of files that are NOT in a list
by dws (Chancellor) on Jul 03, 2002 at 19:22 UTC | |
|
Re: Build a list of files that are NOT in a list
by stajich (Chaplain) on Jul 03, 2002 at 20:00 UTC |