in reply to Re: Compare 2 arrays
in thread Compare 2 arrays
#!usr/bin/perl use strict; use warnings; my $files = "C:/Directory"; my $list = "C:/Test.sdf"; my %keepList; open my $namesIn, '<', $list or die "Failed to open file: $!\n"; # minor updates to this loop ##################### while (my $line = <$namesIn>) #updated ####### { my $sdf_file; #next unless ($sdf_file) = $line =~ /(\w+\.nfo)"$/; #this regex should work equally well next unless ($sdf_file) = $line =~ /(\w+\.nfo)/; $keepList{$sdf_file} = 1; print "keeping $sdf_file\n"; #update for debugging ####### } close $namesIn; opendir my ($filesScan), $files or die "unable to open dir $!"; while (my $filename = readdir $filesScan) { next unless -f "$files/$filename"; #only simple files allowed #skip . and .. or other dirs next if exists $keepList{$filename}; unlink "$files/$filename" or warn qq{cannot delete $filename: $!+} +; } closedir $filesScan;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Compare 2 arrays
by niceguy (Initiate) on Jun 28, 2016 at 15:58 UTC | |
by Marshall (Canon) on Jun 28, 2016 at 18:34 UTC |